0% found this document useful (0 votes)
33 views

Puter Practical

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Puter Practical

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Q1) Write a python program to perform arithmetic operations using variables.

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:")

n5=int(input("Enter roll no."))

n1=int(input("Enter marks of Subject 1(Out of 100):"))

n2=int(input("Enter marks of Subject 2(OUt of 100):"))

n3=int(input("Enter marks of Subject 3(Out of 100):"))

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

radian = float(input('Radius of sphere: '))

sur_area = 4 * pi * radian **2

volume = (4/3) * (pi * radian ** 3)

print("Surface Area is: ", sur_area)

print("Volume is: ", volume)

Output:
Q4) Write a Python Program to compute Simple Interest and Compound Interest.

CODE:

P=int(input("Enter Principal Amount:"))

T=int(input("Enter Time Period (in years):"))

R=float(input("Enter Interest Rate:"))

#process to calculate simp,e interst and compound interest

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:

m=int(input("Enter Any Number:"))

n=m/2

if m%2==0:

print("ENTERED NUMBER IS EVEN")

else:

print("ENTERED NUMBER IS ODD")

OUTPUT:
Q6) Write a python program to find entered number is positive or negative or zero. Print
appropriate message respectively.

CODE:

n=int(input("Enter Any Number:"))

if n==0:

print("ENTERED NUMBER IS ZERO")

if n<0:

print("ENTERED NUMBER IS NEGATIVE")

if n>0:

print("ENTERED NUMBER IS POSITIVE")

OUTPUT:
Q7) Write a python program to enter three numbers and find maximum and minimum numbers.
Print appropriate message respectively.

CODE:

n=float(input("Enter Any Number :"))

m=float(input("Enter Any Number:"))

s=float(input("Enter Any Number:"))

if n>m and n>s:

print("Maximum Number is ",n)

else:

print("Minimum Number is ",n)

if n<m and m>s:

print("Maximum Number is ",m)

else:

print("Minimum Number is",m)

if s>m and n<s:

print("Maximum Number is ",s)

else:

print("Minimum Number is",s)

OUTPUT:
Q8) Write a python program to find and print factorial of entered number .

CODE:

n=int(input("Enter Any Number:"))

factorial=1

if n<0:

print("Sorry,Factorial does not exist")

elif n==0:

print("The Factorial Is 1")

else:

for i in range(1,n+1):

factorial=factorial*i

print("The Factorial of Number is :",factorial)

OUTPUT:
Q9) Write a python program to find entered number is prime or not. Print appropriate message
respectively.

CODE:

n=int(input("Enter Any Number:"))

if n>1:

for i in range(2,int(n/2)+1):

if (n % i) == 0:

print("Entered Number Is Not A Prime Number",n)

break

else:

print("Enterd Number Is A Prime Number",n)

else:

print("Enterd Number Is A Prime Number",n)

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:

N=int(input("Enter Any Number?(enter 2+value):"))

first=0

second=1

print("Fibonacci Numbers Series are :")

print(first,",",second ,end =",")

for i in range (2,N):

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:"))

print("The",s,"reverse order is :")

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:

print(s,"is NOT a Palindrome")

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

print("Number Of Uppercase Letters:",uppercount)

print("Number Of lowercase Letters:",lowercount)

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:")

b=input("Enter the number too be found:")

if b in a:

print(b,"Is there in the list")

else:

print("no element found")

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)

print("The Minmum Element is:",m)

print("Index of minimum element is:",p.index(m))

OUTPUT:
Q18) Write a python program to count the frequency of a given element in a list of numbers.

CODE:

B=int(input("How many elements for the list:"))

a=[]

print("Enter the elements...")

for i in range (B):

a.append(int(input(">>")))

count=int(input("Enter element to count its frequency:"))

print("Given List",a)

print("Frequency of",count,"in the list is:",a.count(count))

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:"))

print("Original list is:",A1)

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]

print("List after swapping is:",A1)

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:

K1=int(input("Enter how many numbers you want to enter:"))

H=[]

G=[]

negative=[]

for i in range(K1):

number=int(input())

H.append(number)

for i in range (K1):

if H[i]>=0:

G.append(H[i])

else:

negative.append(H[i])

print("All Positive Numbers are :",G)

print("All Negative Numbers are :",negative)

print("All Numbers are :",H)

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:

print("Tuple has duplicate values")

else:

print("Tuple has no duplicate values")

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:

print("Contains Multiple Maximum elements")

else:

print("Contains only one Maximum Element")

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:

n1=int(input("Enter Marks of Subject 1:"))

n2=int(input("Enter Marks of Subject 2:"))

n3=int(input("Enter Marks of Subject 3:"))

n4=int(input("Enter Marks of Subject 4:"))

n5=int(input("Enter Marks of Subject 5:"))

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")

if avg>60 and avg<74.99:

print("Grade:B")

if avg>50 and avg<59.99:

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:

n=input("Enter Name of students:")

list1=[]

for i in range(1):

name=input(n)

list1.append(name)

tuple1=tuple(list1)

findName=input("Enter name to find:")

for item in tuple1:

if item==findName:

print("Name Found")

else:

print(" Name Not Found")

OUTPUT:
Q26) Write a python program to create a dictionary with 10 keys using loop.

CODE:

dict={}

for i in range (10):

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)

for i in d1.items ():

for x,y in d2.items():

if i==x:

d3[i]=(i+y)

print("Given Dictionaries are:")

print(d1)

print(d2)

print()

print("The Resultant Dictionary:")

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:

name=input("Enter Employee Name:")

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.

 Display the name and phone numbers of all your friends.


 Add new friend’s details.
 Display dictionary in sorted order of names.
 Modify phone number of any existing friend.

CODE:

n = int(input("Enter how many names you want to enter: "))

# initialize empty dictionary

names={}

for i in range(n):

name=input("Enter name of friend: ")

number=input("Enter phone number: ")

names[name]=number #add name number to dictionary

print(names)

names["Arun"]="9877666234" #add new item

print("Modified dictionary ",names)

del names["Arun"] #delete an item

for name in names: #modify first key value

names[name] = "9456356344"

break

print("Amit" in names)

print("dictionary in sorted order")

for i in sorted (names) : #sort the dictionary

print((i, names[i]), end =" ")


Thank you

THE ADITYA BIRLA PUBLIC SCHOOL,KESROL


NAME : DHRUV MAKWANA
CLASS : XI - SCIENCE
ROLL NO : 10
SUBMITTED TO : RUCHA MA'AM

Rucha Ma’am signature:______________

You might also like