0

There is probably a simple answer to this, but I'm new and have no idea what I'm doing as I am learning everything from google and reddit.

My code is:

def primefinder(z):
    primenumber_list=[]
    for y in range(2, z+1):
        if y not in primenumber_list:
            print(y)
            for x in range(y*y,z+1,y):
                primenumber_list.append(x)
q=input('Enter maximum:')
print(primefinder(q))

The error is like this:

Traceback (most recent call last):
  File "primenumber.py", line 9, in <module>
    print(primefinder(q))
  File "primenumber.py", line 3, in primefinder
    for y in range(2, z+1):
TypeError: Can't convert 'int' object to str implicitly

update: I learned how to properly format integers and strings etc. a very long time ago

1 Answers1

0

The input() function by default returns a string as output, you should explicitly covert it into a different type using int(),float() etc.

def primefinder(z):
    primenumber_list=[]
    for y in range(2, z+1):
        if y not in primenumber_list:
            print(y)
            for x in range(y*y,z+1,y):
                primenumber_list.append(x)
q=int(input('Enter maximum:'))
print(primefinder(q))
Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40