Page 48 - ipp11
P. 48
Ans. (a) num = int(input("Enter a three digit number: "))
sum = 0
temp = num
n = len(str(num))
while temp > 0:
digit = temp % 10
sum += digit ** n
temp //= 10
if sum == num:
print(num, "is an Armstrong number.")
else:
print(num, "is not an Armstrong number.")
Or
(b) while True:
print("\n==== MENU ====")
print("1. Check Positive or Negative or Zero")
print("2. Check Even or Odd")
print("3. Find Greatest of 3 Numbers")
print("4. Exit")
choice = int(input("Enter your choice (1-4): "))
if choice == 1:
num = int(input("Enter a number: "))
if num > 0:
print("The number is Positive.")
elif num < 0:
print("The number is Negative.")
else:
print("The number is Zero.")
elif choice == 2:
num = int(input("Enter a number: "))
if num % 2 == 0:
print("The number is Even.")
else:
print("The number is Odd.")
elif choice == 3:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Greatest number is:", a)
elif b >= a and b >= c:
print("Greatest number is:", b)
else:
print("Greatest number is:", c)
elif choice == 4:
print("Exiting program. Thank you!")
break
else:
print("Invalid choice! Please enter between 1 and 4.")
M.18