这个if语句很奇怪它只执行if甚至给出elif的参数

时间:2014-11-16 09:01:06

标签: if-statement controls structure

好的家伙我写了这个脚本,逻辑似乎也很好,但是当我尝试执行这个脚本时,它只执行if 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 (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()     

1 个答案:

答案 0 :(得分:1)

如果始终评估为true,则:您有usr == "Sphere Area" or "sphere area"

在此,"sphere area"将永远为真。

你应该写:usr == "Sphere Area" or usr == "sphere area"