我正在编写一个程序,询问用户的感受,并根据用户输入的内容给出不同的响应。例如,如果您很高兴或心情好,它会在屏幕上打印"很高兴听到"。但是,我不知道如何读取用户输入。我应该尝试什么?(** 中的文本是我需要帮助的(。谢谢!
`name = input('what is your name?')
print('hello '+ name)
you = input('how are you doing today?')
**if you = happy, good, ok:
print('Glad to hear!')
else:
print('I am sorry, I think I can cheer you up.')**
game = input('wanna play hangman?')
print('yay! Ill start it up.')
print('hangman starting up...')`
在此之后,刽子手游戏开始了。
if you in ['good','great','awesome']
是我猜的一种方式......
欢迎来到 StackOverflow!
如果我理解正确,您要做的是字符串比较:
name = input('what is your name?')
print('hello '+ name)
you = input('how are you doing today?')
# ok, we need to compare the input stored in "you"
# first way is to try expected things, and we can lower case it to facilitate.
if you.lower() == 'good' or you.lower() == 'great':
print('Glad to hear!')
# ... rest of the code
或者:
if you.lower() in ['good', 'great', 'awesome']:
print('Glad to hear!')
我相信这就是你需要的:
name = input('what is your name?')
print('hello '+ name)
you = input('how are you doing today?')
if you == 'happy' or you == 'good' or you == 'ok':
print('Glad to hear!')
else:
print('I am sorry, I think I can cheer you up.')
game = input('wanna play hangman?')
print('yay! Ill start it up.')
print('hangman starting up...')