pythonlistdivider

Print all the dividers from a number, unsupported operand type for string and range


I am trying to exercise my python and do exercices. One exercise is to print all dividers of a number.

I thus tried the following:

a = input("give me a number:")
give me a number:34
x = range(0,200)

for elem in x:
    y= a /x
    if y == 0:
        print(y)

I had the following error: "unsupported operand type(s) for /: 'str' and 'range´"

What am I doing wrong?

wWhy is python considering that "a" is a string? Is my understanding correct?


Solution

  • try this...

    a = int(input("give me a number: "))
    for elem in range(2,a+1):
      if a%elem == 0:
        print(elem)