Calculator Code

                               This is calculator code by using python.

                      Your choice while loop use or not.

 while True:
    print("\nCalculator Menu:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Exit")

choice = input("Enter choice (1/2/3/4/5): ")

if choice not in ['1', '2', '3', '4', '5']:
print("Invalid choice! Exiting the calculator. Goodbye!")
break

if choice == '5':
print("Exiting the calculator. Goodbye!")
break

num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == '1':
print("Result:", num1 + num2)
elif choice == '2':
print("Result:", num1 - num2)
elif choice == '3':
print("Result:", num1 * num2)
elif choice == '4':
if num2 == 0:
print("Error! Division by zero.")
else:
print("Result:", num1 / num2)

Comments

Popular posts from this blog

Screen Recording using python.

wallpaper changer.

Find any color from image using python