Python Exercise3

Create an empty dictionary, add four keys and values to the dictionary. Print the keys from the dictionary. dic={} dic[‘O’]=”Oxyzen” dic[‘Ca’]=”Calcium” dic[‘Na’]=”Sodium” dic[‘H’]=”Hydrogen” print(dic) print(dic.keys())   Create a dictionary, dic={‘O’:’Oxyzen’,’Ca’:’Calcium’,’Na’:’Sodium’,’H’:’Hydrogen’}. Print the values from the dictionary. dic={‘O’:’Oxyzen’,’Ca’:’Calcium’,’Na’:’Sodium’,’H’:’Hydrogen’} print(dic) print(dic.values())   Create a dictionary, dic={‘O’:’Oxyzen’,’Ca’:’Calcium’,’Na’:’Sodium’,’H’:’Hydrogen’}. Print the items from the dictionary. dic={‘O’:’Oxyzen’,’Ca’:’Calcium’,’Na’:’Sodium’,’H’:’Hydrogen’} print(dic) print(dic.items())   4.Create a dictionary marks={‘maths’:97,’science’:98,’history’:78}. Remove the key science from the dictionary. marks={‘maths’:97,’science’:98,’history’:78} del marks[‘science’] print(marks)   Create a dictionary marks and clear all the items from the dictionary. marks={‘maths’:97,’science’:98,’history’:78} marks.clear() print(marks)   Create a dictionary, delete the dictionary and check whether the dictionary exists or not. … Continue reading Python Exercise3

Python Exercise2

Write a program to Create a list of strings Sort it Print the last four strings colors=[“Blue”,”Pink”,”Yellow”,”Red”,”White”,”Black”] colors.sort() print(colors) print(colors[-4:])   Write a program to Create a list of numbers (integers and floats) remove the smallest one find out if 9 is there in the list numb=[10,20.5,60.1,40,50.4,8,90] numb.remove(min(numb)) print(numb) print(“9 in numb: “,9 in numb)   Write a program to find the average of elements given in a list. Round of the result to 1. numb=[10,20.5,60.1,40,50.4,8,90] average=sum(numb)/len(numb) print(“Average:{} “.format(round(average,1)))   Create a list colors and add some colors to the list. Find out the length of each element from the … Continue reading Python Exercise2

Python Exercise1

1.Write a program to take input of name and age from the user and print it Eg: Your name is Ganesh, you are 10 years old   name = input(“Enter your name : “) age =  input(“Enter your age : “) print(“Your name is “,name,”, you are “,age,”Years old”)   2.Find the length of your name and print it as Length of your name is : 6 print(“Length of your name is : “,len(name))   3.Create five valid variables and five invalid variables   a=10 _b=20 tup1=40 tup_1=70 __tup3=”test”   #invalid variables #1a=20 #%b=90 #n ame=”Ujwal” #20=”test” #30=40   4.Print … Continue reading Python Exercise1