[英]How do I get a certain response from a certain input
示例 = 如果该人输入 20,则说 20 不是正确答案 我正在尝试使用的当前代码是:
response = (input ('Type a number'))
if response == '5':
print('5 was the correct answer')
添加一个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')
您应该对正确答案使用“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.