【问题标题】:Run Score in a python quiz game在 python 问答游戏中运行分数
【发布时间】:2022-11-06 01:07:26
【问题描述】:

我正在用 python 编写我的第一个项目:一个包含问题、答案和最终分数的测验

question1 = 'When python was created?: '
question2 = 'Who wrote python?: '
question3 = 'How we call an anonymous functions in python?: '

answer1 = '1991'
answer2 = 'Guido van Rossum'
answer3 = 'lambda'

score1 = '10'
score2 = '20'
score3 = '30'

result1 = score1
result2 = score2
result3 = score3
result4 = score1 + score2
result5 = score1 + score3
result6 = score2 + score3
result7 = score1 + score2 + score3
result8 = 0

# Questions

print(question1)
ans1 = input('Enter your answer: ')
print()

print(question2)
ans2 = input('Enter your answer: ')
print()

print(question3)
ans3 = input('Enter your answer: ')
print()

# Answers

if ans1 == answer1:
    print('Correct')
    print('Your score is: ', score1)
else:
    print('False')
    print('Your score is: 0')

if ans2 == answer2:
    print('Correct')
    print('Your score is: ', score2)
else:
    print('False')
    print('Your score is: 0')

if ans3 == answer3:
    print('Correct')
    print('Your score is: ', score3)
else:
    print('False')
    print('Your score is: 0')

print()

# Final Score

if score1 == True:
    print('Your score is: ', result1)
elif score2 == True:
    print('Your score is: ', result2)
elif score3 == True:
    print('Your score is: ', result3)
elif score1 and score2 == True:
    print('Your score is: ', result4)
elif score1 and score3 == True:
    print('Your score is: ', result5)
elif score2 and score3 == True:
    print('Your score is: ', result6)
elif score1 and score2 and score3 == True:
    print('Your score is: ', result7)
else:
    print('Your score is: ', result8)

我相信最终分数部分是部分正确的,但是在运行代码时我无法使用适当的语句来打印最终分数/结果(目前我正在使用分数语句,但我知道这是错误的,因为我已经运行了代码。 ..)

你知道我应该怎么做才能更正我的代码吗?

【问题讨论】:

    标签: python


    【解决方案1】:
    question1 = 'When python was created?: '
    question2 = 'Who wrote python?: '
    question3 = 'How we call an anonymous functions in python?: '
    
    answer1 = '1991'
    answer2 = 'Guido van Rossum'
    answer3 = 'lambda'
    
    score1 = 10
    score2 = 20
    score3 = 30
    
    result1 = score1
    result2 = score2
    result3 = score3
    
    # Questions
    
    print(question1)
    ans1 = input('Enter your answer: ')
    print()
    
    print(question2)
    ans2 = input('Enter your answer: ')
    print()
    
    print(question3)
    ans3 = input('Enter your answer: ')
    print()
    
    # Answers
    
    if ans1 == answer1:
        print('Correct')
        print('Your score is: ', score1)
    else:
        print('False')
        print('Your score is: 0')
    
    if ans2 == answer2:
        print('Correct')
        print('Your score is: ', score2)
    else:
        print('False')
        print('Your score is: 0')
    
    if ans3 == answer3:
        print('Correct')
        print('Your score is: ', score3)
    else:
        print('False')
        print('Your score is: 0')
    
    print()
    
    # Final Score
    final_score = 0
    final_score += score1 if ans1 == answer1 else 0
    final_score += score2 if ans2 == answer2 else 0
    final_score += score3 if ans3 == answer3 else 0
    
    print('Your score is: ', final_score)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多