此问题已在此处找到答案:
如何针对单个值测试多个变量((27个答案)
为什么'a==x或y或z'的计算结果总是为真((五个答案)
两天前关门了。
刚开始学习python,我一直在做一些宠物项目。在这个过程中,我决定使用or操作符。当我将它添加到一个if语句时,它按预期工作,但当我将它添加到其他3个if语句时,它只运行第一个if语句。
while True:
operation = input("What order of operation would you like to use(Addition/A ,Subtraction/S ,Multiplication/M, Division/D)?")
if operation == "Addition" or "a" :
while True:
Set_Number = int(input("Starting Number: "))
counter = Set_Number
print(counter)
number = int(input("Add:"))
add_count = number
counter += add_count
print(f"Your Answer is " + str(counter))
if operation == "Multiplication" or "m" :
while True:
Set_Number = int(input("Starting Number: "))
counter = Set_Number
print(counter)
number = int(input("Multipled By:"))
add_count = number
counter = counter * add_count
print(f"Your Answer is " + str(counter))
if operation == "Division" or "d" :
while True:
Set_Number = int(input("Starting Number: "))
counter = Set_Number
print(counter)
number = int(input("Divided By:"))
add_count = number
counter = counter/add_count
print(f"Your Answer is " + str(counter))
if operation == "Subtraction" or "s" :
while True:
Set_Number = int(input("Starting Number: "))
counter = Set_Number
print(counter)
number = int(input("Subtracted By:"))
add_count = number
counter = counter - add_count
print(f"Your Answer is " + str(counter))
结果
What order of operation would you like to use(Addition/A ,Subtraction/S ,Multiplication/M, Division/D)?m
Starting Number: 8
8
Add:1
Your Answer is 9
Starting Number:
我不知道如何修复。我需要帮助。
暂无答案!
目前还没有任何答案,快来回答吧!