我正在尝试为我的Python类编写一个数学测验程序,但我一直在使用该sum()函数出错.错误是:
'int' object is not iterable.
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import random
import math
def main():
print('This is a simple math quiz that will test your addition skills.\n')
print('\tGood Luck!\n\n')
# Get two random integers
num1 = random.randint(1, 1001)
num2 = random.randint(1, 1001)
print('What is the sum of ', num1, ' and ', num2, '?')
student_answer = int(input('Enter your answer, then press Enter: '))
answer = sum(num1, num2)
if student_answer == answer:
print('Congratulations! You got it right!')
else:
print('Sorry, your answer …Run Code Online (Sandbox Code Playgroud)