此问题已在此处找到答案:
如何将输入读取为数字((10个答案)
12小时前关门。
我试图用python制作一个简单的计算器,但是,不会执行elif块,即使满足其他条件,它也会跳到else条件。
select=input("Please select an operation- \n"
"1. Add \n"
"2. Subtract \n"
"3. Multiply \n"
"4. Divide \n")
number1=input("Enter the first number: \n")
number2=input("Enter the second number: \n")
if select == 1:
print(number_1, "+", number_2, "=",
add(number_1, number_2))
elif select == 2:
print(number_1, "-", number_2, "=",
subtract(number_1, number_2))
elif select == 3:
print(number_1, "*", number_2, "=",
multiply(number_1, number_2))
elif select == 4:
print(number_1, "/", number_2, "=",
divide(number_1, number_2))
else:
print("Invalid input")
1条答案
按热度按时间ikfrs5lh1#
试试这个
add(float(number_1), float(number_2))