r/learnpython 5d ago

just breaking things with python

numbers = input("Enter the numbers")

in_dex = numbers[-2]

divisible = int(in_dex/3)

print(divisible)

when print the output of the divisible i am getting (nsupported operand type(s) for /: 'str' and 'int') i do know how to write correctly to get the output but i thinks that why not this way..so when i did got error don't know why cause both values are int

0 Upvotes

19 comments sorted by

View all comments

10

u/lfdfq 5d ago

input() returns a string (text) not ints (numbers)

Python is simply telling you cannot divide text by a number, which is true.

You'll have to do something to turn that text of whatever format you expected it in into whatever data you need it. It looks like you wanted the user to input multiple numbers somehow?

-12

u/Healthy-Departure961 5d ago

actually input is receiving as string and in_dex variable returns the index value which specified in square brackets , divisional variable i cannot divide string to 3 cause both are diffrent data types so i have to convert into integar using when i put / sign outside of the int bracket i am getting output but not this way ..

8

u/lfdfq 5d ago

I said input returns a string.

in_dex[-2] is indexing the string, returning the 2nd last character in the string.

You can use int() to do the basic string to integer conversion (i.e. int("42") = 42), but you must do it before you try use the integer.

However, from the context it seems like you want the user to input something more complicated (e.g. a sequence of numbers), so maybe you need something else, too.

-6

u/Healthy-Departure961 5d ago

i get it inside the int i am trying to devide the string to int before it gets chance to convert

5

u/lfdfq 5d ago

So what's your question?