+120 XP
Next MissionLesson 2: Talking to Python with Input
So far Python only talked to us using print(). With the input() function, Python pauses everything, holds up a virtual microphone, and waits for you to type an answer and press Enter.
Key Concepts to Remember:
- •The input() Function: Asks the user a question and saves whatever they type into a variable.
- •Text by Default: input() always gives you a String (text). If someone types 5, Python sees it as the text "5".
- •int() for Math: To do math with a typed number, convert it to an integer using int(input("How old are you? ")).
- •F-Strings: To easily insert variables into sentences, write an f before the quotes: f"Hello {player_name}!".
💻Listening and Greeting Example (IDE Syntax Colors)
hero_name = input("Enter your hero name: ")
coins = int(input("How many coins found? "))
print(f"Watch out villains! {hero_name} has {coins + 5} coins!")
💡 input() asks for your name and coins, int() converts the coins for math, and the f-string prints everything cleanly.
💡 Pro Tip: Always put the letter f right in front of the quotation marks when using curly brackets {variable} inside strings.