我一直有这个小程序的麻烦,它完全跳过了if ==“otc”:部分,我尝试过修复它的东西,但我不能让它工作。在使用此代码的python 3.0中遇到问题
print("Hello, what is your name?")
name = input()
if name == "OTC":
print("get out otc!")
elif():
print("Hello! " + name
我一直有这个小程序的麻烦,它完全跳过了if ==“otc”:部分,我尝试过修复它的东西,但我不能让它工作。在使用此代码的python 3.0中遇到问题
print("Hello, what is your name?")
name = input()
if name == "OTC":
print("get out otc!")
elif():
print("Hello! " + name
如果你想检查是否输入具有otc
,你可以将其转换为大写和检查,但如果你要区分大小写不使用上()
修改:
name = input("Hello, what is your name?")
if name.upper() == "OTC":
print("get out otc!")
else:
print("Hello! " + name)
输出:
Hello, what is your name?"otc"
get out otc!
Hello, what is your name?"barny"
Hello! barny
发生在你的代码:
无需打印,因为同样的事情可以用input
功能
没有必要为elif
来完成,因为只有一个条件检查,以便使用else
elif
是一个声明,而不是一个功能,以便去除()
谢谢!我是python新手,但这有帮助! – CPPBro
@CPPBro乐意提供帮助 – The6thSense
这不是有效的代码。另外,具有空元组的elif是否真的有必要?这就是说,为什么3.0? 3.5已经出来,包含许多改进,所以升级! –