小编use*_*319的帖子

Python错误:'int'对象不可迭代

我正在尝试为我的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)

python python-3.x

-1
推荐指数
1
解决办法
2万
查看次数

标签 统计

python ×1

python-3.x ×1