If statement 这个if语句非常奇怪,它只执行if语句,即使给定了elif的参数
好了,伙计们,我写了这个脚本,逻辑看起来也不错,语法也不错,但是当我尝试执行这个脚本时,它只执行if,而不是else或elif???我很困惑,请帮帮我???请试试看我的意思If statement 这个if语句非常奇怪,它只执行if语句,即使给定了elif的参数,if-statement,controls,structure,If Statement,Controls,Structure,好了,伙计们,我写了这个脚本,逻辑看起来也不错,语法也不错,但是当我尝试执行这个脚本时,它只执行if,而不是else或elif???我很困惑,请帮帮我???请试试看我的意思 import math def main(): usr = input('''Please select which task you would like to do?: plese TYPE either "Sphere Area" or "Sphere Volume"''') if (us
import math
def main():
usr = input('''Please select which task you would like to do?:
plese TYPE either "Sphere Area" or "Sphere Volume"''')
if (usr == "Sphere Area" or "sphere area"):
sphereArea()
elif (usr == "Sphere Volume" or "sphere volume"):
sphereVolume()
else:
print("Please try again wrong choices:")
return main()
def sphereArea():
r = eval(input("Please input the radius: "))
sa = float(4 * 3.14 *(r)**3)
print(sa)
def sphereVolume():
a,b,c = eval(input("Please input the Values for A,B,C in the order, please include comas::"))
sv = float(4/3 * 3.14 * a*b*c)
print("The Volume of the sphere is :",sv,"m3")
main()
如果总是计算为true,因为:您有
usr==“球体区域”或“球体区域”
在这种情况下,“球体区域”
将始终为真
您应该写:usr==“球体区域”或usr==“球体区域”