Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

  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’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading