0% found this document useful (0 votes)
6 views6 pages

#Worksheet Solution

The document contains a series of Python programming exercises covering various topics such as input/output, mathematical calculations, string manipulations, data structures, and control flow. Each question includes code snippets that demonstrate specific programming concepts and tasks, such as calculating the area of a circle, checking for palindromes, and managing a list of student names. The exercises are designed to enhance programming skills and understanding of Python syntax and functionality.

Uploaded by

preetkothari50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

#Worksheet Solution

The document contains a series of Python programming exercises covering various topics such as input/output, mathematical calculations, string manipulations, data structures, and control flow. Each question includes code snippets that demonstrate specific programming concepts and tasks, such as calculating the area of a circle, checking for palindromes, and managing a list of student names. The exercises are designed to enhance programming skills and understanding of Python syntax and functionality.

Uploaded by

preetkothari50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

#Worksheet Solution:

#Comment
#Q1
print("#"*10,"Q1","#"*10)
print("Name:","Amar Singh")
print("Class:","XI-Commerce")
print("MOB no:",9427478144)
print("Favorite Game=","Cricket")

#Q2
print("#"*10,"Q2","#"*10)
r=float(input("Enter The Radius:"))#Explicit Conversion (Type Casting)
pi=3.14
ar=pi*r**2
cr=2*pi*r#Operator and oprands
print("Area of circle:",ar,"\nCircumfrence of circle:",int(cr))#"\n"

#Q3
print("#"*10,"Q3","#"*10)
a=int(input("1st no.:"))
b=int(input("2nd no.:"))
print("Qu:",a/b,"R:",a%b)

#Q4
print("#"*10,"Q4","#"*10)
h=float(input("Enter Your Height:")) #5.7
hi=h/2.54
hf=hi/12
print("Height In Feet:",hf,"Height in inches:",hi)

#Q5
print("#"*10,"Q5","#"*10)
x="informatics"
y="Practices"
print(x+" "+y)

#Q6
print("#"*10,"Q6","#"*10)
x=int(input("Enter First Number:"))
y=int(input("Enter Second Number:"))
print((x**2-4)/6+2*(y**2*x**2)-10)
print(1/3*x**2+2/3*x*y+x*y**2)

#Q7
print("#"*10,"Q7","#"*10)
x=y=z=100
a,b,c=x+10,y+20,z+30
print("x=",x,"y=",y,"z=",z,"a=",a,"b=",b,"c=",c)

#Q8
print("#"*10,"Q8","#"*10)
name=input("Enter the name:")
age=int(input("Enter the Age of "+name+":"))
print(name+str(age))

#Q9
print("#"*10,"Q9","#"*10)
print("Hello",end=" ")
print("Hi",end=" ")
print("good")

#Q10
x="Computer is a Machine\
which needs Electric Current."
print(x[:8])#10(a)
print(x[::-1])#10(b) or x[-1::-1]
print("Length=",len(x))#10(c)

#Q11.

items=int(input("Enter Number of Items="))#We can use eval as well


if items>1 and items<10:
c_p_item=120
print("Total Cost to Pay is ",items*c_p_item)
elif items>=10 and items<=99:
c_p_item=100
print("Total Cost to Pay is ",items*c_p_item)
elif items>=100:
c_p_item=70
print("Total Cost to Pay is ",items*c_p_item)
else:
print("Number of Items must be more or equal to 1")
#######################################
#Q.12
x=input("Enter the word=")
if x==x[-1::-1]:
print("It is a Palindrome")
else:
print("It is not a Palindrome")
##############################################
#Q.13
n=int(input("Enter a Single digit Number="))
if n==0:
print("Zero")
elif n==1:
print("One")
elif n==2:
print("Two")
elif n==3:
print("Three")
elif n==4:
print("Four")
elif n==5:
print("Five")
elif n==6:
print("Six")
elif n==7:
print("Seven")
elif n==8:
print("Eight")
elif n==9:
print("Nine")
else:
print("Only postive and single Digit Number are allowed")
###################################
#Q.14.a)
for i in range(1,41,3):
print(i,end=" ")
#Q.14.b)
for i in range(1,26):
print(i**2,end=" ")

#Q.15
maximum=0
for i in range(1,6):
num=eval(input("Enter Number "+str(i)+"="))
if num>=maximum:
maximum=num
print("Highest Number=",maximum)

#Q.16
for i in range(5,0,-1):
for j in range(5,i-1,-1):
print(j,end="")
print()
for i in range(1,5):
for j in range(5,i,-1):
print(j,end="")
print()

#Q.17
word=input("Enter the Text=")
for i in range(len(word)):
print(i+1,"=>",word[i])

#Q.18
total=0
for i in range(1,6):
num=eval(input("Enter Product "+str(i)+" Price="))
total+=num
if total>=1000:
print("Congratulations You have won the Gift Hamper")
else:
print("Better Luck Next time")

#Q.19
for i in range(1,101):
if i%5!=0 and i%11!=0:
print(i,end=" ")
#Q.20
import random as rd
gen=rd.randint(0,6)
if gen==6:
print("You are Lucky")
elif gen>=3 and gen<6:
print("You just left short of ",6-gen)
else:
print("You are Unlucky")

#Q.21
stud=[]
print("1.Add\n2.Update\n3.Delte")
#Adding 10 Names:
for i in range(1,11):
name=input("Enter name of student "+str(i)+"=")
stud.append(name)
print(stud)
#Updating Name:
up=input("Enter Student Name to Change=")
if up in stud:
new_name=input("Enter New Name =")
i=stud.index(up)
stud[i]=new_name
print("Name Updated")
print(stud)
else:
print("Name not available in list")

#Deleting Name:
dn=input("Enter Student Name to remove=")
if dn in stud:
stud.remove(dn)
print("Name Removed")
print(stud)
else:
print("Name not available in list")

#Q.22
alpha=[]#We can vem make empty list by list()
j=1
for i in range(97,123):
x=chr(i)
alpha.append(x*j)
j=j+1
print(alpha)

#Q.23
x="red green blue red green blue Yellow red".split()
print(x)
x=dict(zip(x,range(len(x))))
x=list(x.keys())
print(x)

#Q.24
first="sun moon jupiter stars venus mars".split()
second="sun moon jupiter planet stars mars".split()
for i in range(len(first)):
if first[i]!=second[i]:
print("The second list differs from index",i,"=",first[i])
break
#Q.25
import random as rd
num=[]
d2=[]
for i in range(1,51):
x=rd.randint(1,20)
num.append(x)
for j in num:
if j%2==0:
d2.append(j)
print("First List=",num)
print("Second List which divisble by 2=",d2)

#Q.26
s1="Surat Bardoli Vadodra Ahemdabad Anand".split()
s2="Mumbai Nasik Pune Nagpur Kohlapur".split()
s3="Jaipur Udaipur Jaselmer Sirohi Mount_Abu".split()
s_c=dict(zip(["GJ","MH","RJ"],[s1,s2,s3]))
print("Unsorted Dictionary\n",s_c)
for i in s_c:
s_c[i]=sorted(s_c[i])
print("Sorted Dictionary\n",s_c)

#Q.27
stud={}
for i in range(3):
r_no=input("Enter roll Number of student"+str(i+1)+"=")
name=input("Enter the name of "+str(r_no)+"=")
surname=input("Enter the Surname of "+name+"=")
age=int(input("Enter the age of "+name+" "+surname+"="))
stud[r_no]=[name,surname,age]
print(stud)

#Q.28
d1={"a":10,"b":20,"c":45,"d":19}
d2={"x":45,"a":10,"s":78,"d":19}
d3={}
for i in d1:
if i in d2:
if d1[i]==d2[i]:
d3[i]=d1[i]
print(d3)
#Q.29
sports={}
for i in range(10):
sp=input("Enter Sports Name "+str(i+1)+"=")
pl=int(input("Enter No. of players="))
sports[sp]=pl
print(sports)

#Q.30
p_book={"Amit":9427478144,"Jay":9723513584,"Chirag":8574858452}
print(p_book)

#Q.a
print("Name\t Number")
for i in p_book:
print(i,"\t",p_book[i])

#Q.b
na=input("Enter name of the friend=")
ph=int(input("Enter Number of"+na+"="))
p_book[na]=ph
print("Name\t Number")
print(p_book)

#Q.c
dt=input("Enter the Friend Name to delete=")
if dt in p_book:
p_book.pop(dt)
print("Removed")
print(p_book)
else:
print("No such friend")

#Q.d
ut=input("Enter the Friend Name to change number=")
if ut in p_book:
no=int(input("Enter New number of "+ut+"="))
p_book[ut]=no
print("updated")
print(p_book)
else:
print("No Such name to update")

#Q.e
ut=input("Enter the Friend Name to search=")
if ut in p_book:
print("Available")
else:
print("Not Available")
#Q.f
x=sorted(p_book)
print(x)

You might also like