如何在Python中创建评分系统?

时间:2018-05-01 11:41:25

标签: python python-3.x

有人能给我看一个系统的例子吗?当你回答一个问题时,它会给你一分,在测验结束时,它总能告诉我多少我做对了?

这是我到目前为止的代码:

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')

1 个答案:

答案 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语句。