Python, Concept by Concept › Output & Variables
Exercises: Output & Variables
Core: Exercises 1–7 and 12–14 are the main path. Extra practice: Exercises 8–11 and More Practice: Exercises 15–18 add variety. Challenges: Exercises 19–20 are optional stretch work; no core exercise depends on them.
For every exercise, follow the specification and produce the exact output shown. Run your cell and compare every capital letter, space, and punctuation mark with the worked sample. Write the lines directly.
Exercise 1: Welcome Sign
A classroom club wants one clear line at the top of its sign so visitors know they are in the right place.
Specification: Given the string variable club_name, print exactly Welcome to <club_name>! on one line.
Worked sample — given values:
club_name = "Code Crew"
Expected output:
Welcome to Code Crew!
Real program
The real program reads a club name with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 2: Supply Label
A shared shelf needs a tidy label that says what an item is and where it belongs. A short comment will help the next programmer understand the two output lines.
Specification: Given item and location, add a comment that describes the program, then print exactly two lines: Item: <item> and Location: <location>.
Worked sample — given values:
item = "markers"
location = "blue bin"
Expected output:
Item: markers
Location: blue bin
Real program
The real program reads an item and a location with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 3: Repeat the Motto
A practice group says the same short motto three times before it begins. Reusing one variable keeps all three lines consistent.
Specification: Given motto, print its value on three separate lines. Write three print() instructions directly.
Worked sample — given values:
motto = "Keep trying"
Expected output:
Keep trying
Keep trying
Keep trying
Real program
The real program reads a motto with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 4: Full-Name Label
A name tag stores the first and last names separately but must display them together with exactly one space.
Specification: Given first_name and last_name, use string concatenation with + to print exactly Name: <first_name> <last_name>. Do not use an f-string.
Worked sample — given values:
first_name = "Ari"
last_name = "Lopez"
Expected output:
Name: Ari Lopez
Real program
The real program reads a first name and a last name with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 5: Team Greeting
A team dashboard greets one member and reminds them which team they joined. The names change, but the sentence format stays fixed.
Specification: Given member_name and team_name, use one f-string to print exactly Hello, <member_name>! Welcome to <team_name>.
Worked sample — given values:
member_name = "Nia"
team_name = "Blue Rockets"
Expected output:
Hello, Nia! Welcome to Blue Rockets.
Real program
The real program reads a member name and a team name with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 6: Repair the Badge
A badge printer stops before showing its label because one string literal never closes. Read the final traceback line, then repair the punctuation.
Specification: Fix the broken instruction without changing its words so it prints exactly Visitor badge ready!. Put the repaired instruction in an empty cell in your exercises notebook.
Worked sample — broken instruction:
print("Visitor badge ready!)
Expected output after the repair:
Visitor badge ready!
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 7: Club Meeting Reminder
A club reminder needs to save both the club's name and its meeting day before it can print a complete sentence.
Specification: Choose two clear variable names. Write assignments that store a club name and a meeting day, then use both variables to print exactly <club> meets on <day>.
Worked sample:
club_name = "Robotics Club"
meeting_day = "Tuesday"
Expected output:
Robotics Club meets on Tuesday.
Real program
The real program reads a club name and a meeting day with input().
How this is checked: You check this one yourself, against the list below.
The site cannot check this one. Run your program, then tick each item below when your work does it.
Exercise 8: Fixed-Value Greeting
An interactive greeter would usually collect a name from a person. For repeatable notebook practice, the reply is already stored as a fixed string.
The lesson has a runnable-at-home input() cell. For this exercise, keep the provided assignment.
Specification: Given name, print exactly Nice to meet you, <name>! using an f-string.
Worked sample — given values:
name = "Sam"
Expected output:
Nice to meet you, Sam!
Real program
The real program reads a name with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 9: Tidy Fact Card
A club welcome board needs the same four-line layout for every member, with only the three facts changing.
Specification: Given member_name, favorite_color, and home_city, print the title CLUB FACT CARD, then print Name: <member_name>, Favorite color: <favorite_color>, and Hometown: <home_city> on the next three lines.
Worked sample — given values:
member_name = "Jordan"
favorite_color = "orange"
home_city = "Fresno"
Expected output:
CLUB FACT CARD
Name: Jordan
Favorite color: orange
Hometown: Fresno
Real program
The real program reads a member name, a favorite color, and a home city with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 10: Apostrophe Notice
A pickup desk needs a natural-sounding sentence with an apostrophe in the owner's name phrase. Choosing matching quotes keeps the punctuation readable.
Specification: Given owner and item, print exactly <owner>'s <item> is ready. Use the variables in the output and preserve the apostrophe and period.
Worked sample — given values:
owner = "Maya"
item = "notebook"
Expected output:
Maya's notebook is ready.
Real program
The real program reads an owner and an item with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 11: Event Ticket
A small event ticket uses a title, a blank line, and two labeled facts so the important details are easy to scan.
Specification: Given event_name and event_day, print EVENT TICKET, then a blank line, then Event: <event_name> and Day: <event_day>.
Worked sample — given values:
event_name = "Game Night"
event_day = "Friday"
Expected output:
EVENT TICKET
Event: Game Night
Day: Friday
Real program
The real program reads an event name and an event day with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 12: Comma Print
The club board needs two short labels that students can read at a glance.
Specification: Given club and room, write a purpose comment, then use a comma in each print() call to show the two labels with one space after each colon.
Worked sample — given values:
club = "Origami"
room = "B12"
Expected output:
Club: Origami
Room: B12
Real program
The real program reads a club and a room with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 13: Room Sign
A hallway sign combines a building name and room number into one clear direction.
Specification: Given building and room_number, write a purpose comment, then use string + to print exactly the sign shown.
Worked sample — given values:
building = "West"
room_number = "204"
Expected output:
West Wing, Room 204
Real program
The real program reads a building and a room number with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 14: Escape Poem
A tiny poem needs three lines, with the last line indented like a closing note.
Specification: Write a purpose comment. Save the exact poem as one string using \n and \t, then print that string once.
Worked sample — given values:
poem = "Sun comes up\nBirds sing\n\tThe end"
Expected output:
Sun comes up
Birds sing
The end
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: three lines; the last starts with a tab
Exercise 15: More Practice: Predict the Output
A printer has three settings to trace. Work out the visible lines without changing the code.
Specification: Predict the output of each snippet in order. The third snippet has two print() calls but makes one output line.
Worked sample — given values:
print("A", "B")
print("x", "y", "z", sep="-")
print("Go", end="!")
print("Now")
Expected output:
A B
x-y-z
Go!Now
Starter (read-only)
# Write your three predictions as comments; do not run new output code.How this is checked: Checked by comparing your prediction with what the program really prints.
Answer format: several lines
Exercise 16: More Practice: Swap Two Values
Two labels have the wrong saved fruit. A temporary variable can keep one value safe while the other changes.
Specification: Given left and right, swap their saved values using a third variable. Print left: <left> and right: <right> after the swap.
Worked sample — given values:
left = "pear"
right = "plum"
Expected output:
left: plum
right: pear
Real program
The real program reads a left value and a right value with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 17: More Practice: Fix the NameError
A fruit label crashes because the printed name uses different capitalization from the assignment.
Specification: Read the broken instruction, then repair only the variable name so the program prints the saved fruit.
Worked sample — given values:
favorite = "mango"
print(Favorite)
Expected output:
mango
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: one line
Exercise 18: More Practice: Triple-Quote Cat
A fixed cat drawing fits in one triple-quoted string.
Specification: Save the three rows below as one triple-quoted string, with no leading or trailing newline. Print the string once.
Worked sample — given values:
cat = """=^.^=
( )
| |"""
Expected output:
=^.^=
( )
| |
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: three lines with every space kept as shown; the indent on the last line is one space
Exercise 19: Two Member Badges
A welcome table must print two badges with the same format. One pair of variables can hold the first member's facts and then be reassigned for the second member.
Specification: Set member_name and member_color to the first pair of values and print the first two-line badge. Print one blank line, reassign the same two variables to the second pair of values, and print the second badge. Each badge uses Member: <name> followed by Color: <color>. Write the lines directly.
Worked sample — given values:
member_name = "Inez"
member_color = "gold"
# After printing the first badge:
member_name = "Omar"
member_color = "green"
Expected output:
Member: Inez
Color: gold
Member: Omar
Color: green
Real program
The real program reads two member names and their colors with input().
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines
Exercise 20: Error Detective Card
A three-line activity card has two independent mistakes: one variable name changes spelling, and the final string is missing a closing quote. Run the program and read the error that the traceback shows first: a SyntaxError from the unclosed quote. Fix that quote and run the program again. Then fix the NameError that the next run reveals.
Specification: Repair only the mistakes in the broken program so it prints the exact three-line card shown below. Keep the given values and labels unchanged. Put the repaired program in an empty cell in your exercises notebook.
Worked sample — given values:
activity_name = "Puzzle Lab"
room_name = "Room B"
Expected output after both repairs:
ACTIVITY CARD
Activity: Puzzle Lab
Room: Room B
How this is checked: Checked by comparing what your program prints with the expected output.
Answer format: several lines