Python Questions With Solutions
Python Questions With Solutions
Write a Python program which accepts the radius of a circle from the user and
compute the area
import math as M
r=int(input("Enter the radius of a circle: "))
area=M.pi*r*r
print(round(area,2))
def prime():
for Number in range (1,101):
count = 0
for i in range(2, (Number//2 + 1)):
if(Number % i == 0):
count = count + 1
break
prime()
3.Write a Python program to calculate the sum of three given numbers, if the values
are equal then return thrice of their sum
for i in s:
if i in v:
print(i)
sum=0
n=input("Enter any number: ")
for i in n:
sum=sum+int(i)
print(sum)
l=[]
size=int(input("Enter the size of the list: "))
for i in range(size):
n=int(input(f"Enter the number at position {i} : "))
l.append(n)
print(l[::-1])
7. Write a Python program to display the first and last element from the following
list
l=[]
size=int(input("Enter the size of the list: "))
for i in range(size):
n=int(input(f"Enter the number at position {i} : "))
l.append(n)
print(l[0],l[len(l)-1])
names=[]
size=int(input("Enter the size of the list: "))
for i in range(size):
n=input(f"Enter the String at position {i} : ")
names.append(n)
d={}
for i in range(len(names)):
x=names[i]
c=0
for j in range(i,len(names)):
c=names.count(x)
count=dict({x:c})
if x not in d.keys():
d.update(count)
print (d)
l=[]
f=[]
size=int(input("Enter the size of the list: "))
for i in range(size):
n=int(input(f"Enter the number at position {i} : "))
l.append(n)
for j in range(len(l)):
if l[j] not in f:
f.append(l[j])
print(f)
print(d)
d.clear()
print(d)
d[2]='s1'
print(d)