Search code examples
pythonpython-3.xsublimetext3sublimetext

Error when calling an 'input' command in Python 3


So I've used python enough to know that this is really simple code and there isn't really a reason that it shouldn't be working. Essentially, I call an input and the user inputs a day of the week, I haven't assigned functions to each day yet, so I tested the input with an 'else' command which tells you "Invalid input", and then recalls the input and asks you again. I tested it by entering something other than what I have defined, and it returns nothing. It should print out "Invalid input." and then re-ask, but it doesn't.

Am I missing something really subtle, or does Python not work properly in Sublime Text 3?

Note: I am writing in Python3, but I never assigned Sublime Text 3 to use that version, I just assumed that it would already interpret it in the latest version of Python - maybe that's my mistake and if so; please can someone tell me how to fix it.

Here's the code:

def ask_day():
    day = input("What's the day today?: ")
    if day == monday:
        mon()
    elif day == tuesday:
        tue()
    elif day == wednesday:
        wed()
    elif day == thursday:
        thu()
    elif day == friday:
        fri()
    elif day == saturday:
        sat()
    elif day == sunday:
        sun()
    else:
        print("Invalid input. Enter a day of the week in lower-case.")
        ask_day()

def ask_time():
    time = input("Whats the current hour?: ")

def mon():
    pass


ask_day()

ask_time()

And here's the output:

What's the day today?: something else

Like I said, it should re-ask me to enter a day, buuut... nothing. It doesn't end, it just gets stuck.

Fun sidenote: Stop harassing this question, I only asked lol.


Solution

  • Problem

    Sublime Text doesn't support Python's input function. (I know, it's quite annoying at first.) But it's a good thing! It forces you to learn other ways to run your code.

    Solution

    As coders gain experience, they begin to run their programs from the command line.

    • Step 1: Open your terminal
    • Step 2: Run python3 <your-file.py>. If you get an error like command not found, try python <your-file.py>.

    Also

    The words monday, tuesday, etc. should be surrounded by quotes as they are strings, not variables (you're not assigning values to them, they are the values themselves).

    For example: 'monday'

    I hope this helps! More info on running files from the command line here.