Puter Practical
Puter Practical
CODE:
c a+b
p=a*b
lk=c/b
ok=p-a
print(a)
print(b)
print(c)
print(p)
print(lk)
prt(ok)
OUTPUT:
Q2) Write a user interactive python program to generate student marksheet using variables.
CODE:
n4=input("Enter Name:")
p=n1+n2+n3
print("Total:",p)
percentage=(p/300)*100
print("Percentage:",percentage)
OUTPUT:
Q3) write a python program that calculates the volume and surface area of sphere .The program
must first ask user to key in radius value ,r before it performs calculations. The program should
display result of the calculations.Use the following formulas:Surface area S=4 pi R
square ,volume=4/3 pi R cube.
CODE:
pi=22/7
Output:
Q4) Write a Python Program to compute Simple Interest and Compound Interest.
CODE:
s= ((P*R*T)/100)
c= (P*((1+R)/100**T))
print("Simple Interest:",s)
print("Compound Interest:",c)
OUTPUT:
Q5) Write a Python Program to find entered number is even or odd.Print appropriate message
respectively.
CODE:
n=m/2
if m%2==0:
else:
OUTPUT:
Q6) Write a python program to find entered number is positive or negative or zero. Print
appropriate message respectively.
CODE:
if n==0:
if n<0:
if n>0:
OUTPUT:
Q7) Write a python program to enter three numbers and find maximum and minimum numbers.
Print appropriate message respectively.
CODE:
else:
else:
else:
OUTPUT:
Q8) Write a python program to find and print factorial of entered number .
CODE:
factorial=1
if n<0:
elif n==0:
else:
for i in range(1,n+1):
factorial=factorial*i
OUTPUT:
Q9) Write a python program to find entered number is prime or not. Print appropriate message
respectively.
CODE:
if n>1:
for i in range(2,int(n/2)+1):
if (n % i) == 0:
break
else:
else:
OUTPUT:
Q10) Write a python program to print following pattern:
12
123
1234
12345
CODE:
n=5
for i in range(1,7):
for j in range(1,i):
print(j,end="")
print("")
OUTPUT:
Q11) Write a python program to print below pattern.
*****
****
***
**
*
CODE:
n=5
for i in range(5):
for j in range(5,i,-1):
print("*",end="")
print("")
OUTPUT:
Q12) Write a python program to take an integer input from user. Print N Fibonacci numbers .
CODE:
first=0
second=1
next=first+second
print(next,end=",")
first=second
second=next
Output:
Q13) Write a python program to print reverse string.
CODE:
s=(input("Enter A String:"))
length=len(s)
for i in range(-1,(-length-1),-1):
print(s[i])
OUTPUT:
Q14) Write a python program to find entered string is palindrome or not.
CODE:
s= input("Enter A String:")
if (s==s[::-1]):
print(s,"is a Palindrome")
else:
OUTPUT:
Q15) Write a program to input a string and print number of uppercase and lowercase letters in it.
CODE:
n=input("Enter A String:")
lowercount=uppercount=0
for i in n:
if i.islower():
lowercount+=1
elif i.isupper():
uppercount+=1
OUTPUT:
Q16) Write a python program to input a list and search for an element in a given list of numbers.
CODE:
a=input("Enter a List:")
if b in a:
else:
OUTPUT:
Q17) Write a python program to find the minimum element from a list along with its index in the
list.
CODE:
p=[12,52,73,1,84,90,16,72]
print(p)
m=min(p)
print(m)
OUTPUT:
Q18) Write a python program to count the frequency of a given element in a list of numbers.
CODE:
a=[]
a.append(int(input(">>")))
print("Given List",a)
OUTPUT:
Q19) Write a python program to input a a list of numbers and swap elements as even locations
with odd elements.
CODE:
A1=eval(input("Enter a list:"))
B2=len(A1)
if B2%2==0:
B2=B2-1
for i in range(0,B2,2):
A1[i],A1[i+1]=A1[i+1],A1[i]
OUTPUT:
Q20) Write a program to read a list of N integers .Create two new lists ,one having all positive
numbers and other having all negative numbers from given list. Print all three lists.
CODE:
H=[]
G=[]
negative=[]
for i in range(K1):
number=int(input())
H.append(number)
if H[i]>=0:
G.append(H[i])
else:
negative.append(H[i])
Output:
Q21) Write a python program to create any one tuple with atleast 5 elements .And write program
to print alternate elements of a tuple T using whilenloop.
CODE:
T=eval(input("Enter a tuple:"))
t1=()
t2=()
i=0
while i<len(T):
if i%2==0:
t1+=(T[i],)
else:
t2+=(T[i],)
i+=1
print(t1)
print(t2)
OUTPUT:
Q22) Write a python program to check if a tuple contains any duplicate elements or not.
CODE:
F=input("Enter a tuple:")
print(F)
U=tuple(set(F))
if U!=F:
else:
OUTPUT:
Q23) Write a python program to check if there are multiple maximum elements in a tuple or not.
CODE:
t=eval(input("Enter a tuple:"))
mx=max(t)
if t.count(mx)>1:
else:
OUTPUT:
Q24) Write a python program to create a tuple stores marks of 5 subjects and calculate the grade
of the student as per the following.
CODE:
total=(n1+n2+n3+n4+n5)
percentage=(total/500)*100
print("Total Percentage:",percentage)
avg=total/5
print("Total Marks:",total)
print("Average:",avg)
if avg>=75:
print("Grade:A")
print("Grade:B")
print("Grade:C")
if avg <50:
print("Grade:D")
Q25) Write a python program to input names of N students and store them in a tuple . Also ,input
a name from user and find if this student is present in tuple or not.
CODE:
list1=[]
for i in range(1):
name=input(n)
list1.append(name)
tuple1=tuple(list1)
if item==findName:
print("Name Found")
else:
OUTPUT:
Q26) Write a python program to create a dictionary with 10 keys using loop.
CODE:
dict={}
n1=input("Enter dictionary:")
dict.setdefault(n1)
print("Dictionary is")
print(dict)
OUTPUT:
Q27) Write a python program to delete the keys of a dictionary one by one in LIFO order.
CODE:
d={1:'xyz',2:'abc',3:'pol'}
print(d)
print()
while len(d)>=1:
print("Elements deleted",d.popitem())
OUTPUT:
Q28) Write a python program to create a third dictionary from two dictionaries having some
common keys , in way so that the values of common keys are added in the dictionary.
CODE:
d1={"1":100,"2":300,"3":900}
d2={"1":200,"2":400,"8":890}
d3=dict(d1)
d3.update(d2)
if i==x:
d3[i]=(i+y)
print(d1)
print(d2)
print()
print(d3)
OUTPUT:
On next page
Q29) Write a python program to enter names of employees and their salaries as input and store
them in a dictionary.
CODE:
D={}
while True:
S=int(input("Enter Salaries:"))
D[name]=S
print(D)
OUTPUT:
Q30) Write a python program to input your friends names and their phone numbers and store
them in a dictionary as the key value pair.
CODE:
names={}
for i in range(n):
print(names)
names[name] = "9456356344"
break
print("Amit" in names)