Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 我的python程序生成十个随机乘法问题。并告诉用户答案是对还是错,并打印正确答案_Python 3.x - Fatal编程技术网

Python 3.x 我的python程序生成十个随机乘法问题。并告诉用户答案是对还是错,并打印正确答案

Python 3.x 我的python程序生成十个随机乘法问题。并告诉用户答案是对还是错,并打印正确答案,python-3.x,Python 3.x,“else”上出现语法错误。我检查了压痕,一切都是正确的。我正在使用闲置的Python 3.8,请有人告诉我我做错了什么 缩进,else应与if对齐。另外,确保你的问题是字符串而不是数字。最后,你现在的回答可能与问题不符。查看eval函数,仅评估给定问题的答案。它与if一致。但我不知道为什么它仍然给出语法错误。我把问题改成了字符串 My code so far looks like this import random Question1 = '3 * 5' Question2 = '4 *

“else”上出现语法错误。我检查了压痕,一切都是正确的。我正在使用闲置的Python 3.8,请有人告诉我我做错了什么

缩进,
else
应与
if
对齐。另外,确保你的问题是字符串而不是数字。最后,你现在的回答可能与问题不符。查看
eval
函数,仅评估给定问题的答案。它与if一致。但我不知道为什么它仍然给出语法错误。我把问题改成了字符串
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)