如何从特定输入获得特定响应
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")
示例 = 如果此人输入 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")