PYTHON PRACTICAL QUESTIONS :)
Q1. Write a python program to find the largest of given three numbers using if
construct.
CODE:
#program to find largest of 3 numbers a=int(input("Enter
the first number-->")) b=int(input("Enter the second
number-->")) c=int(input("Enter the third number-->"))
if(a>b)and(a>c):
print("The largest number is--> ",a)
elif(b>a)and(b>c):
print("The largest number is--> ",b)
elif(c>a)and(c>b):
print("The largest number is--> ",c) elif(a==b>c):
print("The largest number is--> ",a)
elif(b==c)and(b>a)and(c>a):
print("The largest number is--> ",b)
elif(a==c)and(a>b)and(c>b):
print("The largest number is--> ",a)
elif(a==b==c):
print("All the numbers are equal")
Q2.Write a python program that reads a string
and check whether it is a palindrome string or
not using string function .
CODING:
#program to check whether a program is palindrome or not
txt=input("Enter a string to check if it is a palindrome or not-> ")
rev=txt[::-1]
print("Reversed text is: ",rev) if(rev==txt):
print("The text is a palindrome") else:
print("The text is not a palindrome)
Q3.Write a python program to print the sum of squares of first 100 natural
numbers .
CODING:
Import math
s=0
For i in range(1,101):
sqr=math.pow(i,2)
s=s+sqr
print("The sum of squares of the first 100 natural numbers is: ",s)
Q4.To print the first ‘n’ multiples of given number.
CODING:
#Program to print the first 'n' multiples of given number. num=int(input("enter the
number"))
n=int(input("Enter the number of multiples you want")) print("MULTIPLES ARE")
print('**************’)
for a in range(1,n+1):
res=num*a
print(res)
Q5.Write a program to create a dictionary to store names of states
and their capitals.
CODING:
#Write a program to create a
#dictionary to store names of states and their capitals.
states=dict()
#states={}
n=int(input("Please enter the number of states- "))
for i in range(n):
state=input("Enter the name of the state- ")
capital=input("Enter the name of the capital- ")
states[state]=capital
print("Created dictionary is:",states)
ques=input("Enter the state to display the capital- ")
print(states[ques])
Q6.Write a program to create a dictionary of students to
store names and marks obtained in 5 subjects. Get
values from the user.
CODING:
students={}
n=int(input("How many students are there?"))
for i in range(n):
sname=input("ENTER THE NAME OF THE STUDENT- ")
marks=[]
for j in range(5):
mark=float(input("ENTER THE MARKS- "))
marks.append(mark)
students[sname]=marks
print("CREATED DICTIONARY OF STUDENTS:",students)
Q7.Write a program to count the number of vowels in a user entered
string.
CODING:
s=input("Enter
string:") vowels=0
for i in s:
if i in ['a','e','i','o','u','A','E','I','O','U']:
vowels=vowels+1
print("Number of vowels are:")
print(vowels)