Typed text stands in for input()
On your own computer, replace the first line with typed = input("Name: "). Everything else is the same.
input(prompt) pauses the program, shows the prompt, waits for the user to type a line and press Enter, and returns what they typed as a string. Convert it with int() or float() before calculating, and check it before you trust it. input() does not work in the browser panels on this site, so the examples here use fixed values.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write a program that asks for a name and prints Hello, <name>!. Then write the same program with a fixed value in place of input() so it can run here.
Given the text typed = " 42 ", print the number plus 8.
Given the texts a = "3.5" and b = "1.5", print their sum as a number.
Explain it without notes
What type does input() return? Why does input("Age: ") + 1 fail?
How do you read a whole number from the user, and what can go wrong?
Why do the examples in this course use fixed values instead of input() in the Run button?
What is sys.argv?
Expected output
Hello, Asha
Next year you will be 13
1212
' Asha ' 'Asha'
[Asha]
True False False