ASSINGMENT - 1 Q1) WAP TO SWAP TWO INTEGER 1.) WITHOUT USING THIRD VARAIBLE a = int(input("enter number 1: ")) b = int(input("enter number 2: ")) print("number before swsapping are ",a ,"and " , b) a,b = b,a print("number after swapping are ",a ,"and ",b) 2.) WITH USING THIRD VARIABLE a = int(input("enter number 1: ")) b = int(input("enter number 2: ")) print("number before swsapping are ",a ,"and " , b) c = a a = b b = c print("number after swapping are ",a ,"and ",b) Q2) WAP TO CALCULATE 1.) AREA OF TRIANGLE USING HERON'S FORMULA import math a = int(input("length of 1st side:")) b = int(input("length of 2nd side:")) c = int(input("length of 3rd side:")) s = (a+b+c)/2 area = math.sqrt(s*(s-a)*(s-b)*(s-c)) print(f"area of triangle is: {area} sq. units") 2.) AREA OF CIRCLE import math r = int(input("enter radius:")) area = math.pi * r **2 print(f"area of triangle is: {area} sq. units") 3.) SIMPLE INTEREST P = int(input("enter principal value: ")) t = int(input("enter time: ")) r = int(input("enter rate: ")) SI = (P*t*r)/100 print(f"simple interest is {SI}") Q3) WAP TO FIND QUOTIENT AND REMAINDER a = int(input("enter a number: ")) b = int(input("enter a number: ")) print("quotient is: ", a/b) print("remainder is: ", a%b) Q4) WAP TO CONVERT CELCIUS INTO FAHRENHIET a = int(input("enter temperature in celsius: ")) f = (a * 9/5) + 32 print(f"temperature in fahrenheit is {f}F") Q5) WAP TO FIND DISTANCE BETWEEN TWO POINTS import math print("enter co-ordinates of point A") x1 = int(input("enter x1 : ")) y1 = int(input("enter y1 : ")) print("enter co-ordinates of point B") x2 = int(input("enter x2 : ")) y2 = int(input("enter y2 : ")) d = math.sqrt((x2-x1)**2 + (y2-y1)**2) print("distance between two points is : ",d) ASSINGMENT - 2 Q1) WAP TO FIND LARGEST NUMBER OUT OF THREE NUMBER print("enter three numbers :") a = int(input("enter first number :")) b = int(input("enter seconf number :")) c = int(input("enter third number :")) d = max(a,b,c) print("the maximum number is :",d) Q2) WAP TO CHECK ELIGIBILITY FOR VOTING a = int(input("enter your age: ")) if a >= 18: print("you are eligible for voting") else: print("you are not eligible for voting") Q3) WAP TO DETERMINE GRADE OF STUDENT a = int(input("enter your percentage :")) if a > 90: print("you are grade A student") elif a<=90 and a>80: print("you are grade B student") elif a<=80 and a>70: print("you are grade C student") else: print("you need improvement") Q4) WAP TO CHECK LEAP YEAR a = int(input("enter year: ")) if a%400==0 or (a%4==0 and a%100!=0): print("leap year") else: print("not leap year") Q5) WAP TO PRINT NUMBER BETWEEN 10-30 THAT ARE DIVISIBLE BY 2,3 BOTH for i in range(11,30): if i%2==0 and i%3==0: print(i) Q6) WAP TO CHECK PALLINDROME a = int(input("enter a number to check if it is pallindrome or not: ")) b = a c = 0 while a>0: d = a%10 c = c*10+d a = a//10 if c == b: print(f"{b} is a pallindrome") else: print(f"{b} is not a pallindrome") Q7) WAP TO CALCULATE SUM OF SQUARE OF FIRST N NATURAL NUMBER a = int(input("enter a number till where you want sum of square :")) sum = 0 for i in range(a+1): sum += (i*i) print(sum) Q8) WAP TO PRINT KEYS AND VALUES OF A DICTIONARY USING LOOP thisdict={ "a" : 1, "b" : 'hello', "c" : [2,5.5] } for i,j in thisdict.items(): print("key:",i) print("value:",j) Q9) WAP TO COUNT TOTAL NUMBER OF VOWELS IN A STRING a = str(input("enter your text : ")) count = 0 for i in range(len(a)): if a[i] == "a" or a[i] == "e" or a[i] == "i" or a[i] == "o" or a[i] == "u" or a[i] == "A" or a[i] == "E" or a[i] == "i" or a[i] == "O" or a[i] == "U": count += 1 print(count) Q10) WAP TO PRINT A BBB CCCCC a =chr(64) for i in range(1,6,2): a = chr(ord(a)+1) for j in range(i): print(a,end="") print() Assingment - 3 Q1) WAP to reversed every element of the string n = str(input("Enter a string:\n")) n = n.split() i = [j[::-1] for j in n] m = " ".join(i) print(m) Q2) WAP to capitalised first and last alphabet of every element in string n = str(input("Enter a string:\n")) n = n.split() i = [i[0].capitalize() + i[1:-1] + i[-1].capitalize() for i in n] m = " ".join(i) print(m) Q3) WAP to check if first letter of each word is capital or not in a given string n = str(input("Enter a string:\n")) n = n.split() a = 0 for i in n: if i[0].isupper(): a += 1 if a == len(n): print(True) else: print(False) Q4) WAP to print a star pattern n = int(input("Enter a number \n")) for i in range(n+1): for j in range(n+1-i): print(" ",end="") print("*"*i) Q5) WAP to swap case of each letter in a string n = str(input("Enter a string\n")) a = [i.swapcase() for i in n] m = "".join(a) print(m) Q6) WAP to remove all dublicates from string n = str(input("Enter a string\n")) a = "" for i in n: if i not in a: a += i print(a) Q7) WAP to count even and odd number in a list a = input("Enter numbers separated by spaces:\n") n = list(map(int, a.split())) even = 0 odd = 0 for i in n: if i%2==0: even += 1 else: odd += 1 print(f"total even are {even} and odd are {odd}") Q8) WAP to make a list of sum of numbers of digit in a list a = input("Enter numbers separated by spaces:\n") n = list(map(int, a.split())) result = [] for i in n: sum = 0 for j in str(i): sum += int(j) result.append(sum) print(result) Q9) WAP to distinct words from a tupple a = input("Enter numbers separated by spaces:\n") n = tuple(map(str, a.split())) result = [] for i in n: if i not in result: result.append(i) result = tuple(result) print(result) Q10) WAP to create a list of tuple having a number(from given list) and its cube in a tuple a = input("Enter numbers separated by spaces:\n") n = list(map(int, a.split())) result = [] for i in n: t = [] t.append(i) c = i ** 3 t.append(c) t = tuple(t) result.append(t) print(result) Q11) WAP to make a dictionary in which keys are numbers from 1 to 15 and there values are there square a = [] b = [] for i in range(1,16): a.append(i) for i in a: j = i*i b.append(j) result = {i:j for i,j in zip(a,b)} print(result) Q12) WAP to make a dictionary form a string as a key and there count as a value s = str(input("Enter your string:\n")) l =[] c =[] for i in s: if i not in l: l.append(i) c.append(s.count(i)) dict = dict(zip(l,c)) print(dict) Q13)WAP to count number of words, letters and line in a text file with open('./testing/file_A.txt','r') as f: content = f.read() lines = content.splitlines() words = content.split() letter = 0 for i in words: letter += len(i) print(f"numhber of words are {len(words)} \nnumber of lines are {len(lines)} \nnumber of letters are {letter}") Q14) WAP to copy content of a file into another with open('./testing/file_A.txt','r') as f: content = f.read() with open('./testing/file_B.txt','w') as w: w.write(content) Q15) WAP to print only those words in a file which contain al least two vowels s = str(input("Enter your string to be printed in a file \n")) vowels= 'aeiouAEIOU' with open('./testing/file_B.txt','a') as f: for i in s.split(): count = 0 for j in i: if j in vowels: count += 1 if count >= 2: f.write(f'{i} ') 25 QUESTIONS Q1) WAP to make a half kaju kalti form * a = int(input("Enter a number\n")) for i in range(1,a+1): for j in range(i): print("*", end="") print() for i in range(a-1,0,-1): for j in range(i): print("*", end="") print() Q2) WAP to count total letters, uppercase, lowercase letter in a given string s = str(input('Enter a string\n')) upper, lower, count = 0,0,0 for i in s.split(): for j in i: count += 1 if j.isupper(): upper += 1 if j.islower(): lower += 1 print(f"Total number of letters are {count} \nuppercase letters are {upper} \nlowercase letter are {lower}.") Q3) WAP to write fibonnaci series n = int(input("Enter a number\n")) a = -1 b = 1 for i in range(n+1): c = a+b a = b b = c print(c,end=" ") Q4) WAP to read content of a file and create twon more file named even and odd and separate content of file 1 into those two based on there name with open('input.txt','w') as i: i.write('1 52 5 2 6354 6 198 3 246 523 24 98 6 546 54 6 4 65 4 69 469 84 984 965 45 1 65 1 68 4 5644 644 65 4 694 48 698 4 69586958 49' ) with open('input.txt','r') as i: content = i.read() for i in content.split(): if int(i)%2 == 0: with open('./testing/file_A.txt','a') as e: e.write(f"{i} ") else: with open('./testing/file_B.txt','a') as o: o.write(f"{i} ")