有人能给我看一个系统的例子吗?当你回答一个问题时,它会给你一分,在测验结束时,它总能告诉我多少我做对了?
这是我到目前为止的代码:
def QuestionSet1():
print("Challenge level 1 has being selected.")
print("Can you translate these words into french?")
a=input('Q1. Hello! :')
if 'Bonjour' in a:
score = score + 1
print('Correct!')
elif 'bonjour'in a:
score = score + 1
print('Correct!')
else:
print('Wrong! '+'Its Bonjour')
print('You have finished and scored', score, 'out of 10')
答案 0 :(得分:1)
def QuestionSet1():
print("Challenge level 1 has being selected.")
print("Can you translate these words into french?")
a=input('Q1. Hello! :')
score = 0
if 'bonjour' in a.lower():
score = score + 1
print('Correct!')
else:
print('Wrong! '+'Its Bonjour')
print('You have finished and scored', score, 'out of 10')
在给它一个值之前,你需要引用score
。
您还可以通过将输入转换为小写并检查小写值来删除其中一个if语句。