Page 425 - Ai_417_V3.0_C9_Flipbook
P. 425
Print "Not Armstrong Number"
Step 7 Stop
12. Write a menu-driven program to find the volume of a sphere and a cylinder.
Ans. print("Select the vessel whose volume you want to find: \n1. Sphere\n2. Cylinder")
a = int(input())
pi = 3.14
if(a == 1):
print("Enter the radius of the sphere: ")
r = int(input())
volume = ((4/3)*pi*r*r*r)
print("Volume of the sphere is: ",volume)
elif(a= =2):
print("Enter the radius of the cylinder: ")
r = int(input())
print("Enter the height of the cylinder: ")
h = int(input())
volume = pi*r*r*h
print("Volume of the cylinder is: ",volume)
else:
print("Invalid choice")
C. Write a program for the given instructions.
1. Input three numbers and print the largest of three numbers using the if statement.
Ans. a=int(input("enter first number: "))
b=int(input("enter second number: "))
c=int(input("enter third number: "))
larg=a
if b>larg:
larg=b
if c>larg:
larg=c
print("largest of all is ",larg)
2. Input a number and print the table of the number.
Ans. num=int(input("enter a number "))
for i in range(1,11):
print(num,"×",i,"=",num*i)
3. Input a character and check whether it is an uppercase, lowercase character, or digit, or any other character.
Ans. ch = input("Enter a character:")
if ch>='A' and ch<='Z':
print("Uppercase")
elif ch>='a' and ch<='z':
print("Lowercase")
Introduction to Python 423

