我无法在python 3.5中获得用户的角色

时间:2017-06-19 18:13:14

标签: python-3.x

我正在编写脚本读取用户的路径,当我使用input()raw_input()从用户获取角色时

choice = raw_input()
    if choice[0] is 'y' or 'Y':
        print ("text")
    else:
        print ("another text")

并按 y 或任何键,控制台在if条件中显示 text 。 我将choice[0]更改为choice,问题仍然存在。

1 个答案:

答案 0 :(得分:0)

试试这个: -

choice = input()
if choice[0] == 'y' or choice[0] == 'Y':
    print('text')
else:
    print('another text')

我使用的是python 3.6.1,它对我有用。它可能对你有所帮助。 raw_input()在更高版本3中重命名为input()。