我正在尝试为我的 Python 课程编写一个数学测验程序,但我不断收到sum()函数错误。错误是:
'int' object is not iterable.
这是我的代码:
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 is not correct!')
  print(answer)
main()
def sum(number1, number2): 
    return number1 + number2
错误:
Traceback (most recent call last):
  File "C:\Users\Terrence\Desktop\Python Assignments\Chapter 6\Math Quiz.py", line 29, in <module>
    main()
  File "C:\Users\Terrence\Desktop\Python Assignments\Chapter 6\Math Quiz.py", line 20, in main
    answer = sum(num1, num2)
TypeError: 'int' object is not iterable