Learning Objectives
- Prove you can identify and fix both Syntax and Name errors.
- Demonstrate your understanding of Python's strict grammar rules.
- Use
print()statements creatively to build a visual output. - Document your code using best-practice comments.
Part 1: The Broken Blueprint
Just like in real-world software development, you will spend more time fixing code than writing it from scratch!
A fellow developer tried to write a short story, but their code is full of errors and crashes immediately. Your job is to be the debugging detective.
- Create a file named
story.py. - Paste the broken code below into your file.
- Run the code to trigger the first error. Read the traceback from the bottom up.
- Fix the error.
- CRITICAL STEP: On the same line you just fixed, add a single-line comment (
#) explaining if it was aSyntaxErrororNameError, and exactly what you fixed. - Run the code again to find the next bug, and repeat until the story prints perfectly!
The Broken Story
print("Once upon a time in a digital kingdom...") prnt("There lived a brave programmer.") print("They were tasked with fixing a broken machine) print("The machine was missing a parenthesis" print("But the programmer did not panic.") Print("They read the red text from the bottom up!") print("And finally, the code ran flawlessly.")
Part 2: The ASCII Architect
Now that you have fixed someone else's code, it is time to write your own. We are going to use the print() function to draw a picture using text characters this is known as ASCII Art.
- Create a new file named
profile_card.py. - Use a multi-line comment (
""") at the very top of the file to write your name and today's date. - Use at least 7
print()statements to draw a personalized ID card, a robot, a pet, or any shape you like. - Your art must include your name inside of it.
Here is an example of what ASCII art looks like in code:
""" Author: Your Name Date: Today's Date """
print(" /\_/\ ") print(" ( o.o ) ") print(" > ^ < ") print("---------") print("| CODER |") print("---------")
Hint: You will need to run your code several times to check your terminal and adjust the spaces inside your quotes to make everything line up perfectly!