为什么我的程序不读取其他变量?

问题描述 投票:0回答:1

我是整个编程领域的新手,并在互联网上慢慢地学习了一些东西,但是我似乎找不到解决方案或只是不了解它。程序为什么不读取其他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个回答
0
投票

条件应该为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..")

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

© www.soinside.com 2019 - 2024. All rights reserved.