Input & interaction · About 8 minutes

Make your code listen

The big little idea

input() asks for information and gives it back as a string. Your program can use that answer to do something personal or surprising.

color = input()
print(f"One {color} spaceship, coming up!")

In this playground, type answers into the Program input box before running. Each call to input() takes the next line. Even an answer like 12 arrives as text; int() changes a whole-number string into a number.

Predict, then try: read the example from top to bottom. What do you think it will print? Copy it into the editor below to test your prediction.

Your turn, code explorer.

Read a nickname from input and print Welcome aboard, Captain Nova! when the input is Nova.

Welcome aboard, Captain Nova!
my_adventure.pyPython · in your browser

Edit the code. Then run it. Ctrl / ⌘ + Enter also works.

OutputYOUR IDEAS, ALIVE
Your program’s output will appear here.

Ready when you are. ✦

The first run loads Python. This can take a moment.

Program input For programs that use input()

Add answers before you run. Each input() reads the next line. Use made-up names and details.

Real Python, powered by Pyodide. Standard-library programs work here; desktop windows, turtle graphics, and package installation are not supported by this editor. Programs stop after 10 seconds of execution.

Back to the starting code?

This replaces your edits for this activity. Download your code first if you want to keep it.

A little hint, please

Keep {nickname} inside an f-string. Change the words around it to match the goal.

Show one possible solution

There can be more than one way. Read this version, then try writing it yourself.

nickname = input()
print(f"Welcome aboard, Captain {nickname}!")
Pack this idea for later: Input lets the person using your program change what happens.