使用此代码在python 3.0中遇到问题

时间:2015-08-26 04:45:05

标签: python if-statement

我一直遇到这个小程序的问题,它完全跳过了if ==" otc":部分,我已经尝试过修复它的东西,但我可以&# 39;让它发挥作用。

print("Hello, what is your name?")
name = input()
if name == "OTC":
     print("get out otc!")  
elif(): 
     print("Hello! " + name

1 个答案:

答案 0 :(得分:1)

如果你想检查输入是否有otc你可以将它转换成大写并检查但是如果你想要区分大小写不要使用upper()

<强>修饰:

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是一个声明而不是函数,因此请删除()