【发布时间】:2023-05-01 16:10:01
【问题描述】:
我是python新手,所以请帮忙,我不太了解。
我正在做一个请求命令的项目,如果命令是 = “帮助”,那么它会说明如何使用该程序。我似乎无法做到这一点,每次我尝试使用 if 语句时,它仍然会打印帮助部分,无论该命令是否存在。
示例:有人输入了脚本中不存在的命令,它仍会打印帮助部分。
print("welcome, to use this, please input the options below")
print ("help | exit")
option = input("what option would you like to use? ")
if help:
print("this is a test, there will be an actual help section soon.")
else:
print("no such command")
【问题讨论】:
-
可以使用 if 和 elif programiz.com/python-programming/if-elif-else
-
尝试 ` if option == 'help': print('help')`
标签: python if-statement command