Python input() and print() for Games

How print() and input() work in Python, explained with tiny games: f-strings, turning answers into numbers, and cleaning what the player types.

Every console game is a conversation. print() is the game talking, and input() is the game listening. Master these two and you can build quizzes, story games and guessing games.

print() writes text on a new line. Give it several values separated by commas and it puts spaces between them. An f-string (a string with f in front) lets you drop variables straight into the text inside curly brackets.

example 1 · press Run, then edit and run again

input(): ask the player

input("question ") shows the question, waits for the player to press Enter and gives back what they typed as text. Press Run and answer in the box that appears.

example 2 · press Run, then edit and run again

Numbers from input()

Because input() always returns text, "5" + 1 fails. Turn the answer into a number with int(), but check it first with .isdigit() so a typo doesn't crash the game.

example 3 · press Run, then edit and run again

Clean what players type

💡 Common mistake: comparing input() with a number, like if answer == 5. It's never true, because the answer is the text "5".

Games that use input() and print()

Practise this with 3 of the 20 games:

Frequently asked questions

Why does input() return a string in Python?

The keyboard sends characters, so Python gives you exactly what was typed. You decide whether to turn it into a number with int() or float().

How do I print without a new line?

Use print("text", end=""). The end argument replaces the usual line break.

More Python concepts