Start free

GCSE · 9 exercises

Python input and output

input() waits for one line typed by the user and gives it back as text. Keep it in a variable to use it later.

Each call reads one line, so a program that needs two answers calls input() twice.

name = input()
town = input()
print(f"{name} lives in {town}.")

Watch for: Don't put a question inside input("...") here: the prompt is printed too, and the tests compare everything printed.

Exercises

  1. Hello, nameRead a name and greet that person.Novice
  2. Echo, echoRead a word and print it twice, each time on its own line.Novice
  3. Full nameRead a first name and a last name and print the full name.Novice
  4. Age next yearRead someone's age and say how old they will be next year.Novice
  5. Backwards orderRead three lines and print them in the opposite order.Novice
  6. Swap two valuesRead two lines, a and b, and print them swapped: b first, then a.Novice
  7. A tiny storyRead an animal and a verb, and print a sentence with them.Novice
  8. Favourite foodRead a name and a food, and say who likes what.Novice
  9. InitialsRead a first and a last name and print the initials, each followed by a dot.Novice
Start with “Hello, name”