{"id":"input-prompt","slug":"prompt","title":"Asking the user","text":"The programs in the first module print the same thing every time they run. Most useful programs also take **input**: information the user gives while the program runs. In Python, the command `input` reads one line that the user types.\n\n```python\ncity = input(\"Where do you live? \")\nprint(city)\n```\n\n```input\nLisbon\n```\n\n```output\nWhere do you live? Lisbon\nLisbon\n```\n\nHere is what happens, line by line:\n\n- `input(\"Where do you live? \")` shows the text in the parentheses and then waits. This text is the **prompt**: it tells the user what to type. The program stops right there until the user types a line and presses Enter.\n- What the user typed becomes the result of `input`. The `city =` in front of it stores that text under the name `city`, so the program can use it later. A name that holds a value like this is a **variable**. The next step looks at variables more closely.\n- `print(city)` prints what is stored in `city`: the text the user typed. There are no quotes around `city`, because the program should print the value, not the word \"city\".\n\n### What a run looks like\n\nOn a computer, the user types `Lisbon` right after the prompt, on the same line, and the screen shows it there. The examples on this site show it the same way: the **Input** block above is what the user types, and in the output it appears right after the prompt, followed by a line break. When you check a program here, the tests type the input for you, a different line in each test.\n\nNotice the space at the end of the prompt, just before the closing quote. Without it, the answer sticks to the question: `Where do you live?Lisbon`. The space is part of the prompt, so it goes inside the quotes.\n\n### input without a prompt\n\nThe parentheses can also be empty. Then `input()` shows nothing at all and simply waits, so the typed line appears on a line of its own:\n\n```python\nprint(\"Type a word and press Enter.\")\nword = input()\nprint(word)\n```\n\n```input\nhello\n```\n\n```output\nType a word and press Enter.\nhello\nhello\n```\n\nThe first `hello` is what the user typed, and the second is what the program printed. Both work, but a prompt is usually friendlier: the user sees what to type right where they type it.\n","task":"Fill in the blank so the program asks for the user's favorite color and then prints it. If the user types `green`, the run looks like this:\n\n```\nFavorite color: green\ngreen\n```\n","kind":"fill","seed":"color = [[input]](\"Favorite color: \")\nprint(color)\n","solution":"color = input(\"Favorite color: \")\nprint(color)\n","hints":["The command that reads a line the user types is `input`.","Type only the command's name into the blank: `input`. The prompt in parentheses is already there."],"tests":[{"name":"Test 1","stdin":"green\n","expect":"Favorite color: green\ngreen","hidden":false},{"name":"Test 2","stdin":"purple\n","expect":"Favorite color: purple\npurple","hidden":true}],"require":[],"forbid":[],"more":[{"task":"Write a program that asks for a word with the prompt `Word: ` and prints it between two lines of five stars. If the user types `hello`, the run looks like this:\n\n```\nWord: hello\n*****\nhello\n*****\n```\n","kind":"code","seed":"# Ask for the word, then print the frame.\n","solution":"# Ask for the word, then print the frame.\nword = input(\"Word: \")\nprint(\"*****\")\nprint(word)\nprint(\"*****\")\n","hints":["First read the word into a variable: `word = input(\"Word: \")`. Mind the space after the colon.","Then you need three `print` commands, one for each line of the frame.","The middle one prints the variable, so it has no quotes: `print(word)`."],"tests":[{"name":"Test 1","stdin":"hello\n","expect":"Word: hello\n*****\nhello\n*****","hidden":false},{"name":"Test 2","stdin":"Python\n","expect":"Word: Python\n*****\nPython\n*****","hidden":true}],"require":[],"forbid":[]},{"task":"This program asks its question with `print`, so the user has to type the answer on the next line. Change it so the question is the prompt of `input` and the answer is typed on the same line. If the user types `2`, the run should look like this:\n\n```\nHow many cats do you have? 2\n2\n```\n","kind":"code","seed":"print(\"How many cats do you have?\")\ncats = input()\nprint(cats)\n","solution":"cats = input(\"How many cats do you have? \")\nprint(cats)\n","hints":["Move the question into the parentheses of `input()`, and remove the `print` line that asked it.","The prompt needs a space at its end, inside the quotes: `\"How many cats do you have? \"`."],"tests":[{"name":"Test 1","stdin":"2\n","expect":"How many cats do you have? 2\n2","hidden":false},{"name":"Test 2","stdin":"0\n","expect":"How many cats do you have? 0\n0","hidden":true}],"require":[],"forbid":[]}]}