← All missions

πŸ’¬ Ask the Hero

πŸš€ Getting Started & The Basics

1) What do I need to do?

🎯 Your mission: Hero name generator

Ask two questions with input(): a favourite colour and a favourite animal.

Then print the hero name, like: "Your hero name is The Purple Panther!"

2) What do I need to know?

input() asks a question

input() makes the computer ask a question and wait for you to type an answer.

We store the answer in a variable: name = input("What's your name? ")

Run the example and type your answer in the chat box!

🧰 Your toolkit for this mission

Everything you need to know to finish this lesson on your own:

input()

Asks the player a question and waits for them to type an answer.

How to write it: Put the question in quotes inside the brackets and store the answer in a variable.

colour = input("Favourite colour? ")

Answers are strings

Whatever the player types comes back as text, even if it looks like a number.

How to write it: If they type 10, you get "10" β€” you can't do maths with it yet.

age = input("Age? ")  # "10" as text

int()

Turns text like "10" into a real whole number you can do maths with.

How to write it: Wrap input() inside int(): int(input(...)).

power = int(input("Power level? "))
print(power + 50)

float()

Turns text like "1.5" into a decimal number.

How to write it: Use it when the answer might have a dot in it.

height = float(input("Height? "))

Joining text with +

+ glues strings together with no space.

How to write it: Add your own spaces inside the quotes: "The " + colour + " " + animal.

print("Your hero name is The " + colour + " " + animal + "!")

Think about it

Look at this code. What happens next, and why? Say it in your own words.

print("Hi", name)
Watch & explore β–Ά

Power-up: input() asks a question

See it happen

1 / 3
name = input("Name? ")
Name?
⌨ Type Nova

input asks a question and waits. Nothing happens until you answer.

3) Run the code & terminal output

Code Lab 🐍Playground β€” experiment freely!
Hero Terminal

Press β–Ά RUN and your program's messages appear here!

Hero Headquarters
Hero Headquarters
Your superhero companion

Captain Py

Our next adventure is yours to create.