Program a siege
Write real Python against a world that answers back. Start by printing one line, end by writing a program that hunts for a target it cannot see — picking up variables, if/else, random, input, loops and functions on the way.
Briefing
You are aiming a catapult at a castle, and your only control is Python. Each shot teaches one idea: you print a line, store a number, branch on what you can't see, loop until the wall falls, and finally write a function the game calls itself.
You'll learn to
- Read and write real Python: variables, if/else, loops and functions
- Turn text from input() into a number you can calculate with
- Use random, and a loop that stops on a condition
- Tell printing a result from returning one
Before you write a programOptional warm-upInstructions, variables, loops, and the difference between printing and returning.Say something
print, and asking the world a question
Take aim
Variables, and arithmetic with them
Through the fog
if and else — a program that decides
Battle cries
Lists, and asking for something random
The captain decides
input, and why it is never a number
A volley
for loops — say it once, do it many times
Write the rule down
Functions, and the difference between return and print
Until it falls
while loops, and keeping a record
What comes next
The parts of programming this lab left out