01 / GETTING STARTED · LESSON 04

A conversation with your program

Read live terminal input and convert a numeric answer.

12 min · learn at your pace

Pause for an answer

input("Hostname: ") writes a prompt, waits for a line, and returns a string without the ending newline. In this lab the cursor moves to the terminal. Type your answer and press Enter. An empty line is a real answer: it becomes "". Unicode text is supported, including when pasted.

Even a reply containing only digits is still text. Use int() when you need a whole number. Entering three raises ValueError; you will learn to catch it in the validation lesson. For now, read the error and run again with a whole number.

Keep input separate from stored progress

Your code and completed virtual file changes save in this browser. Answers typed at input prompts are session-only and are not added to command history. Ctrl+D sends end-of-file, which makes input() raise EOFError. Stop or Ctrl+C cancels a waiting program and restarts its worker.

A run permits 30 seconds of active computation and 60 seconds of total input waiting. Checking never pauses for a person: the supplied tests provide deterministic answers to the same input calls. This lets checks cover several names and counts without asking you to repeat them.

Try an example.py
name = input("Your name: ")
print(f"Hello, {name.strip()}!")
YOUR TURN

Put it into practice.

Ask for a hostname, then a whole-number count. Strip surrounding whitespace from the hostname and lowercase it. Print Requested {count} checks for {hostname}, using the converted integer count.

See an explained solution
One way to solve it.py
hostname = input("Hostname: ").strip().lower()
count = int(input("How many checks? "))
print(f"Requested {count} checks for {hostname}")

Input stays at the edge of the program. Conversion makes 03 an integer 3, and normalisation prevents accidental spaces from entering the message.