User input options

Is there a way to make each option in the user input its own line instead of being all bunched up like it is. For example
1 - game_dev
2 - etc
3 - etc
4 - etc
5 - etc

# specialty options to choose from for our recommendation.
game_dev = "c#"
web_dev = "html and CSS"
scientific = "python"
scripting = "lua"
mobile_dev = "swift"

# Collect user attributes to inform our recommendation.
specialty = input("Please chose 1 - 5 on your specialty 1 - game_dev, \
2 - web_dev, 3 - scientific, 4 - scripting, 5 - mobile_dev: ")

Replace , with \n in the string you pass to input() and you’re good to go. \n is a newline character.

You can use """ and the final result will be

input("""
Please chose 1 - 5 on your specialty:
1 - game_dev
2 - web_dev
3 - scientific
4 - scripting
5 - mobile_dev
""")

Thank you both for your responses. I tried both and “”" worked for me. For whatever reason on the Khan Academy interactive IDE /n doesn’t seem to work.

The scape character in python is the backslash, \, not the forward slash /. In this case encapsulating the text inside """ ie


""""

This is one line

This is other line

"""

improves redibillity compared to


"This is one line\nThis is other line"

But you could get the same results because \n represents the whitespace character newline.

Other useful characters are

  • \t is a tab,

  • \r is a carriage return

  • \b is backspace

As \ is the scape character, you can use it to include single and doube quotes inside the strings:


t = "He said \"Hello\""

print(t) # He said "Hello"

1 Like