how to fix TypeError: int() argument must be a string, a bytes-like object or a number, not 'range'

Question:

  number = 0
  for number in int(range(2, 101, 2)):
    number = sum(number)
    print(number)

how do I fix this code. It keeps coming back with

TypeError: int() argument must be a string, a bytes-like object or a number, not ‘range’

Asked By: DJcookie

||

Answers:

What are you trying to do with that?
You don’t need to define ‘number’ and don’t use int() there.

If you want to sum all numbers from 2 to 101 in steps of 2, use this:

num_sum = 0
for i in range(2, 101, 2):
   num_sum += i
   print(num_sum)
Answered By: zHigh
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.