Ask coding questions

← Back to all posts
String input being read as integer in REPL build (Python3)
reddevils1979 (0)

Doing this simple program:

Name = input("Please enter your name: ")
print(Name)

Age = input("Please enter your age: ")
print(Age)

When I run it with REPL in Sublime it takes the name no problem, but when I input the age REPL highlights it as an integer and doesn't receive the input. (When I run it through the terminal it works as intended).

Sorry if the format of this question is off, still trying to figure stuff out.

Thanks!

Answered by DynamicSquid (4899) [earned 5 cycles]
View Answer
Comments
hotnewtop
DynamicSquid (4899)

Could you link your repl?

reddevils1979 (0)

@DynamicSquid Yes, took me a minute to figure out how to upload it, but it's there now. Also I'm using Sublime 3

reddevils1979 (0)

@DynamicSquid Works fine on here too, problem seems to just be in Sublime.

DynamicSquid (4899)

@reddevils1979 I'm not sure what you are asking? Are you trying to convert user input into an integer? If so, use this: int(input("Age: "))

DynamicSquid (4899)

@reddevils1979 That's weird... You could always convert an integer to a string by using str(input("Age: "))

reddevils1979 (0)

@DynamicSquid

In Sublime it's reading the Age input as an integer rather than a string. Wasn't sure if there was a way to fix this

reddevils1979 (0)

@DynamicSquid yeah I just wasn't sure if I was doing something dumb. I'm still new to learning python/coding and trying to set up my workstation and sometimes it seems a bit overwhelming.

DynamicSquid (4899)

@reddevils1979 Yeah, I don't think you're doing anything wrong. Sublime text can be a little confusing sometimes.

But you can always use Replit :)

reddevils1979 (0)

@DynamicSquid yeah I'm trying to follow along on some pirple videos (and reading Python Crash Course), so it can be confusing when the code and result don't exactly match up. I knew I was doing it right since it worked in the Terminal and here, just wasn't sure if I needed to do any more changes to the REPL package in Sublime to make it work in there.

DynamicSquid (4899)

@reddevils1979 It's all good. Good luck with your learning!

reddevils1979 (0)

@DynamicSquid Dumb question: Where is the "answered" button?

DynamicSquid (4899)

@reddevils1979 Just the little check mark next to my comment :)

reddevils1979 (0)

Figured out the issue: The plug-in keyboard I'm using has a keypad on the side and SublimeREPL doesn't recognize it as input. If I use the numbers above the letter keys it works fine. Weird!

LukeWright (285)

instead of

Age = input("Enter your age: ")

you have to do

Age = int(input("Enter your age: ")
print(Age)
LukeWright (285)

By default python reads all inputs as strings so if there is a value that you want to get that is an integer, just use int(input(. you can also convert a string variable to an integer in text by using

intvar = int(strvar)

or vice versa

strvar = str(intvar)
reddevils1979 (0)

@LukeWright Thanks for the response. I don't want it as an integer, I DO want it as a string, but in Sublime it reads the input as an integer. My code works as intended when I run it here and on the Terminal, but when I run SublimeREPL it keeps on reading the number input as an integer rather than a string.

LukeWright (285)

Have you tried specifying that you want it to be a string? It may be that Sublime uses integer as the default input type. You can do this with

stringvar = str(input("Enter a string here! "))

@reddevils1979

reddevils1979 (0)

@LukeWright I think something weird was going on with my reader. Tried typing it exactly the same way again and it's able to finish and close the program as intended.