2. # To calculate Area and Perimeter of a rectangle
L=int(input("Length")) B=int(input("Breadth")) Area=L*B Perimeter=2*(L+B) print("area:", Area) print("Perimeter:",Perimeter) output: Length 15 Breadth 17 area: 255 Perimeter: 64 3. #sample program for string data types str="artificial+intelligence" print(str) print(str[0]); print(str[2:8]) print(str[4:9]) print(str[3]) print(str[3:]) print(str*2) print(str+'good morning') #updating string var1='python programming' print(var1) print(var1[:12]) print("updated string:",var1[:18]+'language') output: artificial+intelligence a tifici ficia i ificial+intelligence artificial+intelligenceartificial+intelligence artificial+intelligencegood morning python programming python progr updated string: python programminglanguage 4. #sample program for list data types list=[29,750,37,12,345,67,89,67,78,89] list1=['home','sweet '] print(list) print(list[0]); print(list[2:8]) print(list[3:9]) print(list[3]) print(list[3:]) print(list1*2 ) print(list+list1) output: [29, 750, 37, 12, 345, 67, 89, 67, 78, 89] 29 [37, 12, 345, 67, 89, 67] [12, 345, 67, 89, 67, 78] 12 [12, 345, 67, 89, 67, 78, 89] ['home', 'sweet ', 'home', 'sweet '] [29, 750, 37, 12, 345, 67, 89, 67, 78, 89, 'home', 'sweet '] 5. #list function() list=[10,20,30,40,50,60] print(list) list.append(70) print(list) list.pop(4) print(list) list.count(60) print(list) list.reverse() print(list) list.sort() print(list) output: [10, 20, 30, 40, 50, 60] [10, 20, 30, 40, 50, 60, 70] [10, 20, 30, 40, 60, 70] 1 [70, 60, 40, 30, 20, 10] [10, 20, 30, 40, 60, 70] 6. #sample program for tuple data types tuple=('physics',786,2.25,'chemistry',750,10,20,30,40) print(tuple); tuple1=('computer',999) print(tuple[0]); print(tuple[2:8]) print(tuple[3:9]) print(tuple[3]) print(tuple[3:]) print(tuple*2 ) print(tuple+tuple1) output: ('physics', 786, 2.25, 'chemistry', 750, 10, 20, 30, 40) physics (2.25, 'chemistry', 750, 10, 20, 30) ('chemistry', 750, 10, 20, 30, 40) chemistry ('chemistry', 750, 10, 20, 30, 40) ('physics', 786, 2.25, 'chemistry', 750, 10, 20, 30, 40, 'physics', 786, 2.25, 'chemistry', 750, 10, 20, 30, 40) ('physics', 786, 2.25, 'chemistry', 750, 10, 20, 30, 40, 'computer', 999) 7. #sample program for condition statement(if…elif…) a = int(input("Enter a number : ")) if a%2 == 0 and a >50: # Even and > 50 print("Your number is even and greater than 50.") elif a%2 == 0 and a <50: # Even and < 50 print("Your number is even and smaller than 50.") elif a%2 == 0 and a == 50: # Even and == 50 print("Your number is even and equal to 50.") else: print ("Your number is odd.",) output: Enter a number : 204 Your number is even and greater than 50. 8. #sample program for condition statement(while.....) n=1 while n<17 : print("square of",n ,"is",n*n) n=n+1 output: square of 1 is 1 square of 2 is 4 square of 3 is 9 square of 4 is 16 square of 5 is 25 square of 6 is 36 square of 7 is 49 square of 8 is 64 square of 9 is 81 square of 10 is 100 square of 11 is 121 square of 12 is 144 square of 13 is 169 square of 14 is 196 square of 15 is 225 square of 16 is 256 9. #sample program for condition statement(for loop.....) num=5 for a in range(1, 11): print(num,'x',a,'=',num*a) output: 5x1=5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50 10. . #sample program for condition statement( dictionary') dict={} dict['one']='this is dictionary' dict[2]='python programming' tinydict={'name':'priya','code':1080,'dept':'admin'} print(dict['one']) print(dict[2]) print(tinydict) print(tinydict.keys()) print(tinydict.values()) output: this is dictionary python programming {'name': 'priya', 'code': 1080, 'dept': 'admin'} dict_keys(['name', 'code', 'dept']) dict_values(['priya', 1080, 'admin'])