为什么我的程序不读取其他变量?
Why isnt my program not reading the other variables?
我是整个编程的新手,慢慢地在互联网上学习了一些东西,但我似乎无法找到解决方案或者只是不理解它。为什么程序不读取其他 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..")
条件应为 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..")
如果答案回答了您的问题,请标记为正确答案。
我是整个编程的新手,慢慢地在互联网上学习了一些东西,但我似乎无法找到解决方案或者只是不理解它。为什么程序不读取其他 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..")
条件应为 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..")
如果答案回答了您的问题,请标记为正确答案。