1. Generate Armstrong Numbers
def is_armstrong(num):
power = len(str(num))
total = sum(int(digit) ** power for digit in str(num))
return total == num
n = int(input("Enter the range up to which you want to find Armstrong numbers: "))
print(f"Armstrong numbers up to {n}:")
for i in range(n+1):
if is_armstrong(i):
print(i, end=" ")
2. Generate Area of Shapes
import math
def area_of_shapes():
shapes = {"1": "Circle", "2": "Rectangle", "3": "Triangle", "4": "Square"}
print("Choose a shape:", ", ".join(f"{k}. {v}" for k, v in shapes.items()))
choice = input("Enter your choice (1-4): ")
if choice == "1":
radius = float(input("Enter radius: "))
area = math.pi * radius ** 2
elif choice == "2":
length, width = map(float, input("Enter length and width: ").split())
area = length * width
elif choice == "3":
base, height = map(float, input("Enter base and height: ").split())
area = 0.5 * base * height
elif choice == "4":
side = float(input("Enter side: "))
area = side ** 2
else:
print("Invalid choice")
return
print(f"Area: {area:.2f}")