Python Forum

Full Version: Trouble converting a string into an int
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi team,

So I'm writing a simple program that asks for a user input of an integer, and then I need to convert that object into an argument that int() will accept so I can use bin() to retrieve the binary output but nothing I try seems to work. Incoming code:

#user inputs integer
Line 2: numb = input('Enter an integer >')
print(numb)
#numb here is a literal int string bound to the input of numb

numb =(input('Enter it again >' ))

#convert and bind object numb into a str
int(numb)
Line 9: bin1 = bin(numb)

#final output
print(bin1)


At line 9 I get the "builtins.Typeerror:'str' object cannot be interpreted as an integer" even though I thought I converted the object type previously...I'm stumped! I don't understand how the object 'numb' isn't converted into an int since the previous line shows no errors. Any ideas?
You need to save the integer after you convert it
numb = int(numb)
OMG you instantly solved that. I didn't realize I had to recall the numb object into the int() function. Thank you, good human.