简体   繁体   English

如何从某个输入中获得某个响应

[英]How do I get a certain response from a certain input

Example = If the person types in 20, say that 20 was NOT the correct answer My current code that I'm trying to work with is:示例 = 如果该人输入 20,则说 20 不是正确答案 我正在尝试使用的当前代码是:

response = (input ('Type a number'))
if response == '5':
print('5 was the correct answer')

Add an else and use f-strings to insert the user's input into your response:添加一个else并使用 f-strings 将用户的输入插入到您的响应中:

answer = input('Type a number')
if answer == '5':
    print(f'{answer} was the correct answer')
else:
    print(f'{answer} was NOT the correct answer')

You should use an "if" condition for your correct answer, and an else for incorrect ones, while also using proper indents:您应该对正确答案使用“if”条件,对不正确答案使用 else,同时使用适当的缩进:

correct = 5
response = input('Type a number: ')
if response == correct:
    print('5 was the correct answer')
else:
    print(response, "was NOT the correct answer")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM