py ws 3
py ws 3
4.hr=int(input("Enter hour:"))
c=int(input("Enter am(1) or pm(2):"))
hh=int(input("Enter how many hrs to go ahead:"))
if c==1:
nt=hr+hh
if(nt>12):
t=nt-12
print(t,' pm')
else:
print(nt,' am')
elif c==2:
nt=hr+hh
if(nt>12):
t=nt-12
print(t,' am')
else:
print(nt,' pm')
1 --- 1
2 --- 4
3 --- 9
4 --- 16
5 --- 25
6 --- 36
7 --- 49
8 --- 64
9 --- 81
10 --- 100
11 --- 121
12 --- 144
13 --- 169
14 --- 196
15 --- 225
16 --- 256
17 --- 289
18 --- 324
19 --- 361
20 --- 400
10.n=int(input("Enter a number:"))
f=1
for i in range (1,n+1):
f=f*i
print("Factorial of",n,"is",f)
15.sum=0
for i in range(0,31):
sum=sum+(i+1/31-i)
print("Thw sum of the series is:",sum)
16.cal=4.2
for i in range(10,31,5):
print(cal*i)
17.count=0
for i in range(1,6):
print("Enter the bugs for day ",i)
b=int(input())
count+=b
print("Total bugs collected is:",count)
Output:
Enter the bugs for day 1
2
Enter the bugs for day 2
3
Enter the bugs for day 3
4
Enter the bugs for day 4
5
Enter the bugs for day 5
6
Total bugs collected is: 20
18.c=0
n=1
while(c<50):
for i in range(2,n//2):
if n%i==0:
continue
else:
print(n,',',end="")
c+=1
if c%10==0:
print("\n")
19.
w=int(input("Enter your weight:"))
for i in range(1,16):
print("Your weight on moon after ",i," years")
w+=w*0.165
print(w)
print("The total weight after 15 years is:",w)
20.import math
for i in range(0,346,15):
print(i,"---",math.sin(i),math.cos(i))
Output:
0 --- 0.0 1.0
15 --- 0.6502878401571168 -0.7596879128588213
30 --- -0.9880316240928618 0.15425144988758405
45 --- 0.8509035245341184 0.5253219888177297
60 --- -0.3048106211022167 -0.9524129804151563
75 --- -0.38778163540943045 0.9217512697247493
90 --- 0.8939966636005579 -0.4480736161291701
105 --- -0.9705352835374847 -0.24095904923620143
120 --- 0.5806111842123143 0.8141809705265618
135 --- 0.08836868610400143 -0.9960878351411849
150 --- -0.7148764296291646 0.6992508064783751
165 --- 0.9977972794498907 -0.06633693633562374
180 --- -0.8011526357338304 -0.5984600690578581
195 --- 0.21945466799406363 0.9756226979194443
210 --- 0.46771851834275896 -0.8838774731823718
225 --- -0.9300948780045254 0.36731936773024515
240 --- 0.9454451549211168 0.32578130553514806
255 --- -0.5063916349244909 -0.8623036078310824
270 --- -0.1760459464712114 0.9843819506325049
285 --- 0.7738715902084317 -0.6333425312327234
300 --- -0.9997558399011495 -0.022096619278683942
315 --- 0.7451332645574127 0.6669156003948422
330 --- -0.13238162920545193 -0.9911988217552068
345 --- -0.5439958173735323 0.8390879278598296
21.while(1):
w=eval(input("Enter your weight in kg:"))
if w<0:
print("Weight cant be negative")
break
w=w*2.20
print("Your weight in pounds is",w)
22.while True:
print("Metric Conversion Menu:")
print("1. Pounds to Grams")
print("2. Grams to Pounds")
print("3. Inches to Centimeters")
print("4. Centimeters to Inches")
print("5. Kilometers to Miles")
print("6. Miles to Kilometers")
print("7. Exit")
ch=int(input("Enter choice:"))
if ch==1:
pounds=float(input("Enter pounds: "))
g=ppunds*453.592
print(f"{pounds} pounds is {(g):.2f} grams.")
elif ch==2:
g=float(input("Enter grams: "))
p=g/453.592
print(f"{g} grams is {p:.2f} pounds.")
elif ch==3:
i=float(input("Enter inches: "))
cm=i*2.54
print(f"{i} inches is {cm:.2f} centimeters.")
elif ch==4:
cm=float(input("Enter centimeters: "))
i=cm/2.54
print(f"{cm} centimeters is {i:.2f} inches.")
elif ch==5:
km=float(input("Enter kilometers: "))
m=km*0.6123
print(f"{km} kilometers is {m:.2f} miles.")
elif ch==6:
m=float(input("Enter miles: "))
km=m/0.6123
print(f"{m} miles is {km:.2f} kilometers.")
elif ch==7:
print("Exiting the program.")
break
else:
print("Invalid choice. Please select a valid option.")
23.n1=int(input("Enter number 1:"))
n2=int(input("Enter number 2:"))
if n1>n2:
max=n1
min=n2
else:
max=n2
min=n1
while True:
if min!=0:
r=max%min
max=min
min=r
elif min==0:
print("The GCD of the two numebrs is:",max)
break
24.import random as r
userp = aip = 0
ch = ["Rock", "Paper", "Scissors"]
print("""1 for Rock
2 for Paper
3 for Scissors""")
k =5
userw = [13, 21, 32]
aiw = [12, 23, 31]
for i in range(k):
userc =int(input("Enter : "))
if(userc not in [1,2,3]):
print("Wrong input")
k+=1
continue
aic = r.randint(1,3)
Output:
26.
n=int(input("Enter the number of teams in the tournament: "))
total=0
while n>1:
if n%2==0:
matches=n//2
n=n//2
else:
matches=(n-1)//2
n=(n-1)//2+1
total+=matches