首页 > 解决方案 > 我的 python 程序生成十个随机乘法问题。并告诉用户答案是对还是错并打印正确的答案

问题描述

My code so far looks like this

import random
Question1 = '3 * 5'
Question2 = '4 * 8'
Question3 = '3 * 4'
Question4 = '2 * 3'
Question5 = '5 * 5'
Question6 = '7 * 7'
Question7 = '8 * 5'
Question8 = '9 * 8'
Question9 = '2 * 7'
Question10 = '10 * 8'
Answer1 = 15
Answer2 = 32
Answer3 = 12
Answer4 = 6
Answer5 = 25
Answer6 = 49
Answer7 = 40
Answer8 = 72
Answer9 = 14
Answer10 = 80
questions = [Question1,Question2,Question3,Question4,Question5,Question6,Question7,Question8,Question9,Question10]
answers = [Answer1,Answer2,Answer3,Answer4,Answer5,Answer6,Answer7,Answer8,Answer9,Answer10]
random.shuffle(questions)
random.shuffle(answers)
if questions[0] == Question1:
print(Question1)
user_input = int(input('Enter the answer: '))
    if user_input == Answer1:
        print('right')
        else:
            print('wrong')
            print('The correct answer is:',Answer1)

我在“else”上收到语法错误。我检查了压痕,一切都是正确的。我正在使用 IDLE Python 3.8,请有人指导我做错了什么。

标签: python-3.x

解决方案


推荐阅读