من برای ایجاد یک ماشین حساب ساده ، کد پایتون پیدا کردم.

ماشین حساب DEF ():
چاپ (“به ماشین حساب پایتون خوش آمدید!”)
چاپ (“یک عملیات را انتخاب کنید:”)
چاپ (“1. افزودنی (+)”)
چاپ (“2. تفریق (-)”)
چاپ (“3. ضرب
“)
# Get user input for operation
operation = input("Enter the number corresponding to the operation (1/2/3/4): ")
if operation not in ['1', '2', '3', '4']:
print("Invalid input. Please restart and choose a valid operation.")
return
try:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
except ValueError:
print("Invalid input. Please enter numeric values.")
return
if operation == '1':
result = num1 + num2
print(f"The result of {num1} + {num2} is {result}")
elif operation == '2':
result = num1 - num2
print(f"The result of {num1} - {num2} is {result}")
elif operation == '3':
result = num1 * num2
print(f"The result of {num1} * {num2} is {result}")
elif operation == '4':
if num2 == 0:
print("Error: Division by zero is not allowed.")
else:
result = num1 / num2
print(f"The result of {num1} / {num2} is {result}")
از حالت تمام صفحه خارج شوید
ماشین حساب ()