├── 10-12-2021 ├── prgm34.py ├── prgm35.py ├── prgm36.py ├── prgm37.py ├── prgm38.py ├── prgm39.py ├── prgm40.py └── prgm41.py ├── 12-11-2021 ├── prgm12.py ├── prgm13.py ├── prgm14.py ├── prgm15.py ├── prgm16.py ├── prgm17.py ├── prgm18.py ├── prgm19.py └── prgm20.py ├── 19-11-2021 ├── prgm21a.py ├── prgm21b.py ├── prgm21c.py ├── prgm21d.py ├── prgm22.py ├── prgm23.py ├── prgm24.py └── prgm25.py ├── 26-11-2021 ├── prgm26.py ├── prgm27.py ├── prgm28.py ├── prgm29.py ├── prgm30.py ├── prgm31.py ├── prgm32.py └── prgm33.py ├── 29-10-2021 ├── prgm1.py ├── prgm10.py ├── prgm2.py ├── prgm3.py ├── prgm4.py ├── prgm5.py ├── prgm6.py ├── prgm7.py ├── prgm8.py └── prgm9.py └── README.md /10-12-2021/prgm34.py: -------------------------------------------------------------------------------- 1 | # 34. Program to find the factorial of a given number using user-defined function. 2 | 3 | def factorial(n): 4 | fact = 1 5 | for i in range(1, n+1): 6 | fact = fact * i 7 | return fact 8 | number = int(input("Enter the range:")) 9 | result = factorial(number) 10 | print("fact=", result) 11 | -------------------------------------------------------------------------------- /10-12-2021/prgm35.py: -------------------------------------------------------------------------------- 1 | # 35. Add ‘ing’ at the end of a given string. If it already ends with ‘ing’, then add‘ly’. 2 | # (Use user defined function) 3 | 4 | a = input("Enter a string:") 5 | def lying(str1): 6 | if a[-3:] != 'ing': 7 | print(a + "ing") 8 | else: 9 | print(a + "ly") 10 | lying(a) 11 | -------------------------------------------------------------------------------- /10-12-2021/prgm36.py: -------------------------------------------------------------------------------- 1 | # 36. Generate all factors of a number. (Use user defined function) 2 | 3 | a = int(input("Enter a number:")) 4 | def factor(num): 5 | for i in range(1, num+1): 6 | if num % i == 0: 7 | print(i) 8 | factor(a) 9 | -------------------------------------------------------------------------------- /10-12-2021/prgm37.py: -------------------------------------------------------------------------------- 1 | # 38. Generate a list of four-digit numbers in a given range with all 2 | # their digits even and the number is a perfect square. 3 | 4 | def perfectSquares(l, r): 5 | 6 | for i in range(l, r+1): 7 | 8 | if (i ** (.5) == int(i ** (.5))) and (i % 2 == 0): 9 | print(i, end=" ") 10 | 11 | l = int(input ("Enter a 4 digit lower limit:")) 12 | r = int(input ("Enter a 4 digit upper limit:")) 13 | 14 | perfectSquares(l, r) 15 | -------------------------------------------------------------------------------- /10-12-2021/prgm38.py: -------------------------------------------------------------------------------- 1 | # 38. Generate a list of four-digit numbers in a given range with all 2 | # their digits even and the number is a perfect square. 3 | 4 | def perfectSquares(l, r): 5 | 6 | for i in range(l, r+1): 7 | 8 | if (i ** (.5) == int(i ** (.5))) and (i % 2 == 0): 9 | print(i, end=" ") 10 | 11 | l = int(input ("Enter a 4 digit lower limit:")) 12 | r = int(input ("Enter a 4 digit upper limit:")) 13 | 14 | perfectSquares(l, r) 15 | 16 | -------------------------------------------------------------------------------- /10-12-2021/prgm39.py: -------------------------------------------------------------------------------- 1 | # 39. Write lambda functions to find area of square, rectangle and triangle 2 | 3 | t_area = lambda b,h : 0.5 * (b * h) 4 | r_area = lambda len, ht : len*ht 5 | s_area = lambda leng : leng * leng 6 | print("Area of Triangle is:", t_area(10,20)) 7 | print("Area of Rectangle is:", r_area(30,20)) 8 | print("Area of Square is:", s_area(15)) -------------------------------------------------------------------------------- /10-12-2021/prgm40.py: -------------------------------------------------------------------------------- 1 | # 40.count the number of characters in a string 2 | 3 | a = input("Enter the string:") 4 | count = 0 5 | for i in range(0, len(a)): 6 | if (a[i] != ' '): 7 | count = count + 1 8 | print("Total number of characters in a string: " + str(count)) 9 | -------------------------------------------------------------------------------- /10-12-2021/prgm41.py: -------------------------------------------------------------------------------- 1 | # 41. Construct following pattern using nested loop 2 | 3 | n = int(input("Enter the number of rows")) 4 | for i in range(0, n): 5 | for j in range(0, i + 1): 6 | print("*", end=" ") 7 | print() -------------------------------------------------------------------------------- /12-11-2021/prgm12.py: -------------------------------------------------------------------------------- 1 | a = (123, "234", "567", "hai") 2 | print(a) 3 | -------------------------------------------------------------------------------- /12-11-2021/prgm13.py: -------------------------------------------------------------------------------- 1 | a = {"fruit":"apple", "drink":"Tea","city":"melattur"} 2 | print(a["drink"]) 3 | print (a) 4 | -------------------------------------------------------------------------------- /12-11-2021/prgm14.py: -------------------------------------------------------------------------------- 1 | age = int(input("Enter the age:")) 2 | if age >= 18: 3 | print("Eligible for vote") 4 | else: 5 | print("not eligible") 6 | -------------------------------------------------------------------------------- /12-11-2021/prgm15.py: -------------------------------------------------------------------------------- 1 | color = str(input("Enter the color")) 2 | if color == 'red' or color == 'RED': 3 | print("stop") 4 | elif color == 'green' or color == 'GREEN': 5 | print("go") 6 | elif color == 'orange' or color == 'ORANGE': 7 | print("slow down") 8 | else: 9 | print("Invalid value") 10 | -------------------------------------------------------------------------------- /12-11-2021/prgm16.py: -------------------------------------------------------------------------------- 1 | a = int(input("Enter the first number:")) 2 | b = int(input("Enter the second number:")) 3 | x = ("+","_","*","/") 4 | print(x) 5 | ch = input("Enter the operator:") 6 | if(ch=='/'): 7 | if(a==0): 8 | print("Division not possible") 9 | else: 10 | print("division answer=",a/b) 11 | elif(ch=='+'): 12 | print("addition answer=",a+b) 13 | elif (ch=='-'): 14 | print("subtraction answer=",abs(a-b)) 15 | elif (ch=='*'): 16 | print("multiplication answer=",a*b) 17 | -------------------------------------------------------------------------------- /12-11-2021/prgm17.py: -------------------------------------------------------------------------------- 1 | for letter in 'python': 2 | print(letter) 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /12-11-2021/prgm18.py: -------------------------------------------------------------------------------- 1 | char=input("Enter the character:") 2 | print(char) 3 | for i in char: 4 | print(i) -------------------------------------------------------------------------------- /12-11-2021/prgm19.py: -------------------------------------------------------------------------------- 1 | limit=int(input("Enter the limit")) 2 | for i in range(1,limit): 3 | if(i%2==0): 4 | print(i+2) 5 | -------------------------------------------------------------------------------- /12-11-2021/prgm20.py: -------------------------------------------------------------------------------- 1 | yeara = 2021 2 | yearb= int(input("Enter the limit:")) 3 | print("list of year") 4 | for year in range(yeara, yearb): 5 | if (year % 4 == 0) and (year % 100 != 0) or (year % 400 == 0): 6 | print(year) 7 | -------------------------------------------------------------------------------- /19-11-2021/prgm21a.py: -------------------------------------------------------------------------------- 1 | #A-Generate positive list of numbers from a given list of integer 2 | import matplotlib.pyplot as plt 3 | list = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6] 4 | nlist = [i for i in list if i > 0] 5 | 6 | students=[40,55] 7 | plt.pie(students) 8 | plt.show()(nlist) -------------------------------------------------------------------------------- /19-11-2021/prgm21b.py: -------------------------------------------------------------------------------- 1 | #B-Square of N numbers 2 | n=int(input("Enter the number:")) 3 | nlist = [i*i for i in range (1,n+1)] 4 | print(nlist) -------------------------------------------------------------------------------- /19-11-2021/prgm21c.py: -------------------------------------------------------------------------------- 1 | #C-Form a list of vowels selected from a given word 2 | 3 | n = input("Enter a word:") 4 | nlist = [i for i in n if i == "a" or i == "e" or i == "i" or i == "o" or i == "u" or i == "A" or i == "E" or i == "I" or i == "O" or i == "U"] 5 | 6 | print(nlist) -------------------------------------------------------------------------------- /19-11-2021/prgm21d.py: -------------------------------------------------------------------------------- 1 | #D-List ordinal value of each element of a word (Hint:use ord() to get ordinal values) 2 | 3 | word = (input("Enter a word:")) 4 | nlist = [ord(i) for i in word] 5 | print(nlist) -------------------------------------------------------------------------------- /19-11-2021/prgm22.py: -------------------------------------------------------------------------------- 1 | # Get a string from an input string where all occurrences of first character replaced with ‘$’, except first character. 2 | n = input("enter the string") 3 | c = n[0] 4 | for i in n: 5 | if i == c: 6 | n = n.replace(i, '$') 7 | n = c + n[1:] 8 | print(n) 9 | -------------------------------------------------------------------------------- /19-11-2021/prgm23.py: -------------------------------------------------------------------------------- 1 | #Prompt the user for a list of integers. For all values greater than 100, store ‘over’ instead. 2 | list1 = [] 3 | n = int(input("Enter a limit:")) 4 | print("Enter the list of integers:") 5 | for i in range(n): 6 | ele = int(input()) 7 | if ele > 100: 8 | list1.append('d') 9 | else: 10 | list1.append(ele) 11 | print(list1) 12 | -------------------------------------------------------------------------------- /19-11-2021/prgm24.py: -------------------------------------------------------------------------------- 1 | #Find biggest of 3 numbers entered 2 | a = int(input("Enter three numbers:")) 3 | b = int(input()) 4 | c = int(input()) 5 | if a > b and a>c: 6 | greater = a 7 | elif b>a and b>c: 8 | greater = b 9 | else: 10 | greater = c 11 | print("Greater: ", +greater) 12 | -------------------------------------------------------------------------------- /19-11-2021/prgm25.py: -------------------------------------------------------------------------------- 1 | #Accept a file name from user and print extension of that. 2 | name= [] 3 | fname = input("Enter the filename:") 4 | name = fname.split(".") 5 | extension = name[1] 6 | print("The extension of the file is : .",extension) 7 | -------------------------------------------------------------------------------- /26-11-2021/prgm26.py: -------------------------------------------------------------------------------- 1 | a = "python" 2 | b = a[0] 3 | c = a[1:-1] 4 | d = a[-1] 5 | e = d + c + b 6 | print(e) 7 | -------------------------------------------------------------------------------- /26-11-2021/prgm27.py: -------------------------------------------------------------------------------- 1 | # 26. Create a list of colors from comma-separated color names entered by user. Display first and last colors. 2 | a = input("Enter the colors separated with commas") 3 | b = a.split(",") 4 | print("1st element", b[0]) 5 | print("last element", b[-1]) 6 | 7 | -------------------------------------------------------------------------------- /26-11-2021/prgm28.py: -------------------------------------------------------------------------------- 1 | # 27.Print out all colors from Set1 not contained in Set2. 2 | a = {'red', 'green', 'blue'} 3 | b = {'red', 'white', 'black'} 4 | c = a-b 5 | print(c) 6 | -------------------------------------------------------------------------------- /26-11-2021/prgm29.py: -------------------------------------------------------------------------------- 1 | # 28. Create a single string separated with space from two strings by swapping the character at position 1 2 | a = input("Enter the 1st words:") 3 | b = input("Enter the 2nd words:") 4 | c = a[0] 5 | d = b[0] 6 | print(c, d, "\n") 7 | e = a[1:] 8 | f = b[1:] 9 | print(e, f, "\n") 10 | g = d + e 11 | h = c + f 12 | print(g+" "+h) 13 | 14 | -------------------------------------------------------------------------------- /26-11-2021/prgm30.py: -------------------------------------------------------------------------------- 1 | # 29. Merge two dictionaries. 2 | a = {'name': 'alan', 'age': '21'} 3 | b = {'place': 'melattur', 'state': 'kerala'} 4 | a.update(b) 5 | print(a) 6 | 7 | 8 | -------------------------------------------------------------------------------- /26-11-2021/prgm31.py: -------------------------------------------------------------------------------- 1 | # 30.From a list of integers, create a list removing even numbers 2 | a = [1, 2, 3, 4, 5, 6, 7, 8] 3 | print("list:", a) 4 | b =[ i for i in range(0, 8) if a[i] % 2 == 0] 5 | print(b) 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /26-11-2021/prgm32.py: -------------------------------------------------------------------------------- 1 | # 31. Find the sum of all items in a list. 2 | a = [1, 2, 3, 4, 5] 3 | sum = 0 4 | 5 | for i in range(0, 5): 6 | sum = sum + a[i] 7 | print(sum) 8 | -------------------------------------------------------------------------------- /26-11-2021/prgm33.py: -------------------------------------------------------------------------------- 1 | n = int(input("Enter the value of 'n': ")) 2 | a = 0 3 | b = 1 4 | sum = 0 5 | count = 1 6 | print("Fibonacci Series: ", end = " ") 7 | while(count <= n): 8 | print(sum, end = " ") 9 | count += 1 10 | a = b 11 | b = sum 12 | sum = a + b -------------------------------------------------------------------------------- /29-10-2021/prgm1.py: -------------------------------------------------------------------------------- 1 | a=10 2 | b=20 3 | c=30 4 | print (a) 5 | print (b) 6 | print (c) 7 | -------------------------------------------------------------------------------- /29-10-2021/prgm10.py: -------------------------------------------------------------------------------- 1 | r=int (input(" Enter the radius:")) 2 | h=int (input(" Enter the height:")) 3 | v=3.1415*(r*r)*h 4 | print("volume=",v) -------------------------------------------------------------------------------- /29-10-2021/prgm2.py: -------------------------------------------------------------------------------- 1 | a = 10 2 | b = 20 3 | area = a * b 4 | print(area) 5 | -------------------------------------------------------------------------------- /29-10-2021/prgm3.py: -------------------------------------------------------------------------------- 1 | #welcome to python 2 | #sum of num1 and num2 3 | num1=10 4 | num2=20 5 | c=num1+num2 6 | print (c) -------------------------------------------------------------------------------- /29-10-2021/prgm4.py: -------------------------------------------------------------------------------- 1 | #(0°C × 9/5) + 32 = 32°F 2 | a=float (input(" Enter the temperature in celsius:")) 3 | b=(a * 9/5) + 32 4 | print ("fahrenheit=",b) -------------------------------------------------------------------------------- /29-10-2021/prgm5.py: -------------------------------------------------------------------------------- 1 | a=float(input("Enter the distance in km:")) 2 | b=(a/ 1.609) 3 | print ("miles=",b) -------------------------------------------------------------------------------- /29-10-2021/prgm6.py: -------------------------------------------------------------------------------- 1 | a=int (input(" Enter the 1st number:")) 2 | b=int (input(" Enter the 2nd number:")) 3 | print("before swap a=",a) 4 | print("before swap b=",b) 5 | temp=a 6 | a=b 7 | b=temp 8 | print("after swap a=",a) 9 | print("after swap b=",b) -------------------------------------------------------------------------------- /29-10-2021/prgm7.py: -------------------------------------------------------------------------------- 1 | a=int (input(" Enter the radius of circle:")) 2 | b=2*3.1415*a 3 | print ("area=",b) -------------------------------------------------------------------------------- /29-10-2021/prgm8.py: -------------------------------------------------------------------------------- 1 | n=input("enter the name") 2 | a=int (input(" Enter the mark of sub1:")) 3 | b=int (input(" Enter the mark of sub2:")) 4 | c=int (input(" Enter the mark of sub3:")) 5 | d=int (input(" Enter the mark of sub4:")) 6 | e=int (input(" Enter the mark of sub5:")) 7 | sum=a+b+c+d+e 8 | per=((a+b+c+d+e)/500) *100 9 | print(n) 10 | print("sum=",sum) 11 | print("percentage=",per) 12 | -------------------------------------------------------------------------------- /29-10-2021/prgm9.py: -------------------------------------------------------------------------------- 1 | a=float (input(" Enter the distance in feet:")) 2 | b=(a * 12) 3 | print ("inches=",b) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pythonlab --------------------------------------------------------------------------------