【问题标题】:Why isnt my program not reading the other variables?为什么我的程序没有读取其他变量?
【发布时间】:2019-12-01 11:18:38
【问题描述】:

我是整个编程的新手,慢慢地在互联网上找到了一些东西,但我似乎找不到解决方案,或者只是不明白。为什么程序不会读取其他 elif 语句?这是我的第一个项目。生病感谢任何提示和建议。欢迎提出任何建议和意见,谢谢!

#inputing
unknown = " "
while unknown != "exit":
    unknown = input("Please enter unknown: ").lower()
    angle = int(input("Please enter given angle: "))
#if base
    if unknown == "base" or "a":
        side = input("Height(b) or Hypotenuse(c)? ").lower()
        if side == "height" or "b":
            height = int(input("Please enter given height: "))
            base = int(height * tan(radians(angle)))
            print(">> The base is: " + str(base))
        else:
            hypotenuse = int(input("Please enter given hypotenuse: "))
            base = int(hypotenuse * cos(radians(angle)))
            print(">> The base is: " + str(base))

#if height
    elif unknown == "height" or "b":
        side = (input("Base(a) or Hypotenuse(c)?  ")).lower()
        if side == "base" or "a":
            base = int(input("Please enter given base: "))
            height = int(input(base * tan(radians(angle))))
            print(">> The height is: " + str(height))
        else:
            hypotenuse = int(input("Please enter given hypotenuse: "))
            height = int(hypotenuse * cos(radians(angle)))
            print(">> The height is: " + str(height))
    elif unknown == "exit":
        break
    else:
        print("I don't understand that..")

【问题讨论】:

    标签: python-3.x math trigonometry


    【解决方案1】:

    条件应为if unknown == "base" or unknown == "a":elif unknown == "height" or unknown == "b":

    unknown == "base" or "a" 中,第一个条件为 False unknown == "base" 并且 "a" 为 True,这导致结果为 True "a"

    #inputing
    unknown = " "
    while unknown != "exit":
        unknown = input("Please enter unknown: ").lower()
        angle = int(input("Please enter given angle: "))
    #if base
        if unknown == "base" or unknown == "a":
            side = input("Height(b) or Hypotenuse(c)? ").lower()
            if side == "height" or "b":
                height = int(input("Please enter given height: "))
                base = int(height * tan(radians(angle)))
                print(">> The base is: " + str(base))
            else:
                hypotenuse = int(input("Please enter given hypotenuse: "))
                base = int(hypotenuse * cos(radians(angle)))
                print(">> The base is: " + str(base))
    
    #if height
        elif unknown == "height" or unknown == "b":
            side = (input("Base(a) or Hypotenuse(c)?  ")).lower()
            if side == "base" or "a":
                base = int(input("Please enter given base: "))
                height = int(input(base * tan(radians(angle))))
                print(">> The height is: " + str(height))
            else:
                hypotenuse = int(input("Please enter given hypotenuse: "))
                height = int(hypotenuse * cos(radians(angle)))
                print(">> The height is: " + str(height))
        elif unknown == "exit":
            break
        else:
            print("I don't understand that..")
    

    如果回答了您的问题,请将答案标记为正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-19
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 2011-06-30
      • 1970-01-01
      相关资源
      最近更新 更多