Python fundamentals walkthrough, from Hello World to a guessing game
The first exercise in the free Agent Games Python Fundamentals course takes one line to greet the world. By the twelfth, you can build a game that picks a secret number, gives the player hints and keeps score. The walkthrough takes about 69 minutes. If you’re coding along, pause at the start of each exercise and try it before watching the solution. Watch the introduction at 0:00
How do you get Python to greet someone by name?
Start by printing a greeting exactly as you want it to appear. In print("Hello, World!"), the quotation marks tell Python where the text begins and ends. The comma and exclamation mark inside them appear on screen. 3:20 · Hello, World!
Now imagine the greeting comes from a spaceship. Store the captain’s name in a variable, then use it in the welcome message. Change name = "Bob" to your own name and run it again. The same print statement now welcomes a different captain. 4:15 · Welcome Aboard
What if you only find out who’s at the keyboard after the program starts? With name = input("What is your name? "), Python pauses for a reply. Type a name and press Enter. The next line can use that reply to greet you. 6:37 · Hello, Human
Ask for an age as well, and you have two pieces of text to fit into a sentence. An f-string lets you write the sentence in reading order. In f"{name} is {age} years old.", Python fills each pair of braces with the current value of the variable inside. 8:46 · Name and Age
When does an answer need to become a number?
An age can go straight into a greeting as text. To work out how old someone will be next year, the program needs to do arithmetic. Try entering 12. The reply arrives as the string "12", and int(age) turns it into the integer you can add one to. The same conversion lets you work out last year’s age or look a decade ahead. 11:10 · Age in the Future
A reply can also determine which line runs next. In the greeting exercise, name == "Maya" asks a question with a true or false answer. An if checks the first name, each elif gives another name its own greeting, and the final else handles a stranger. Try both Maya and maya to see how precisely Python compares strings. 17:05 · Who Goes There?
The grade calculator uses the same branching structure with ranges of scores. A good way to test yours is to enter 89, 90, then 101. The first two should land on opposite sides of the B/A boundary. The third is outside the grading scale altogether. Those three runs tell you whether you’ve handled the edge of a grade and the edge of the scale. 21:45 · Grade Calculator
How do you transform text and repeat an action?
In Name Shout, the challenge is to make a name sound like someone calling across a room. Start with Mia. The string method .upper() gives you MIA, then doubling each vowel with .replace() gives you MIIAA. Each method returns a new string, so keep its result for the next change. 30:02 · Name Shout
Repeated Greetings starts with five hellos and then asks how many more you want. A for loop over range(5) runs its indented line five times. For the second loop, the user supplies the count. Try entering zero. You’ll still see the original five greetings, and the second loop will finish without printing another. 35:05 · Repeated Greetings
Return to the age calculation and try to break it. What should happen if someone types twelve? What about 121? Check the Age gives those replies different messages. It checks the text with .isdigit() before calling int(), then checks whether the resulting age exceeds 120. Only an accepted age reaches the decade calculation. 38:30 · Check the Age
What changes when a guessing game keeps score?
Seven Guesses ties input, comparisons and repetition together. Pick a secret number once with random.randint(1, 100), then give the player up to seven attempts. Keeping that line before the loop matters. If the target changed on every turn, the previous hint would tell the player nothing about the next guess. A correct guess ends the loop early with break. 51:03 · Seven Guesses
The last exercise changes one rule. The player starts with ten points, and each wrong numeric guess costs one. A typing mistake earns a prompt to try again and leaves the score alone. That means you can’t tell in advance how many times you’ll need to ask for input. The condition while not found and score > 0 expresses exactly when to ask again. 1:00:54 · Guess with a Score
Try one final experiment in your own copy. Set the secret to 50 for a round, then enter hello, 25 and 50. Can you predict the final score before you press Enter? It should be nine. If you get a different result, follow the score through each of those three turns. You now have a repeatable way to test a game that usually depends on luck. Try the free Python course





