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 textint()
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 / 3name = input("Name? ")input asks a question and waits. Nothing happens until you answer.
3) Run the code & terminal output
Press βΆ RUN and your program's messages appear here!


Captain Py
Our next adventure is yours to create.
