python-3.x - 我的 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,请有人指导我做错了什么。
解决方案
推荐阅读
- angular - 点击后清空Angular typeahead输入
- excel - 使用 openpyxl 在 Excel 工作表中插入动态数组公式
- c++ - 构造函数不分配
- spring - Spring Boot 应用程序容器化连接到两个 mysql 容器
- jquery-ui - 动态添加 jquery 可排序元素后,拖动并调整元素大小并获取 jquery 中的位置
- signalr - JQuery 信号器正在工作,但轮询每 2 秒循环一次
- java - 运行带有或不带有 .java 文件扩展名的 java 文件有什么区别
- tsql - T-SQL - 将多个值解析为多行
- r - R中两个变量相关的计算
- asp.net-core - 切换到开发环境会显示更详细的信息