# Initialize Otter
import otter
grader = otter.Notebook("02_lab_python_basics.ipynb")
Cane Card Registration System¶
Goal: Build a student registration data processor for the University of Miami's Cane Card office.
Welcome to the Cane Card Office!¶
You've been hired as a student worker at the Cane Card Office. Your job is to help process new student registration data.
The problem? Students submit their information in different formats:
- Some use feet and inches, others use centimeters
- Some provide weight in pounds, others in kilograms
- Birth dates need to be converted to ages
Your task: Build a data processing system that standardizes all this information into a consistent format for the university database.
By the end of this lab, you'll have built a complete profile processor that takes messy real-world input and produces clean, formatted output like this:
===== CANE CARD PROFILE =====
Name: Maria Garcia
C-Number: C12345678
Enrollment Year: 2026
Height: 68 in (172.72 cm)
Weight: 165 lbs (74.8 kg)
Age: 21 (Adult: Yes)
Temperature: 98.6°F (37.0°C)
=============================
Reference: You can look back at 02_python_basics.ipynb from lecture for syntax help!
Important: Run cells in order from top to bottom. Later questions use variables from earlier questions.
# Validation: Check Python version and file location
import os
import sys
# Supported Python versions for this course
SUPPORTED_VERSIONS = ["3.12", "3.13"]
current_version = f"{sys.version_info.major}.{sys.version_info.minor}"
if current_version not in SUPPORTED_VERSIONS:
raise EnvironmentError(
f"Python version mismatch!\n"
f"Supported: {', '.join(SUPPORTED_VERSIONS)}\n"
f"Found: {current_version}\n"
f"Please use Python 3.12 or 3.13 for this course."
)
print(f"Python version: {current_version}")
# Expected filename for this assignment
EXPECTED_FILE = "02_lab_python_basics.ipynb"
# Check file is in the correct directory
current_path = os.path.abspath("")
required_path_segment = os.path.join("Documents", "CSC115", "lab_notebooks")
allowed_envs = ["submission", "dist", "live", "source"]
in_allowed_env = any(env in current_path for env in allowed_envs)
if required_path_segment not in current_path and not in_allowed_env:
raise EnvironmentError(
f"File location error!\n"
f"This notebook should be in: ~/Documents/CSC115/lab_notebooks/\n"
f"Current location: {current_path}\n"
f"Please move this file to the correct directory."
)
# Verify directory name and filename (skip in grading/development environments)
if not in_allowed_env:
if not os.path.exists(EXPECTED_FILE):
notebooks = [f for f in os.listdir(".") if f.endswith(".ipynb")]
raise EnvironmentError(
f"Filename mismatch!\n"
f"Expected: {EXPECTED_FILE}\n"
f"Found notebooks: {notebooks}\n"
f"Please rename your notebook to '{EXPECTED_FILE}'."
)
print(f"File location: {os.path.join(current_path, EXPECTED_FILE)}")
Part 1: Student Identity¶
Every Cane Card needs basic identification information. Let's start by storing a student's core data.
Question 1: Student Identity Variables (1 point)¶
Create the following variables with exactly these names:
| Variable Name | Type | Description | Example |
|---|---|---|---|
student_first_name |
string | Student's first name | "Maria" |
student_last_name |
string | Student's last name | "Garcia" |
student_c_number |
string | C-Number (must start with "C") | "C12345678" |
enrollment_year |
integer | Year of enrollment (no quotes!) | 2026 |
Requirements:
- Use your own name or make one up
- C-Number must be exactly 9 characters: the letter "C" followed by 8 digits
- Enrollment year must be a number, NOT a string (no quotes around it)
# ✏️ YOUR CODE HERE
# Create the four variables described above
student_first_name = ...
student_last_name = ...
student_c_number = ...
enrollment_year = ...
# Let's see what you created
print(f"Name: {student_first_name} {student_last_name}")
print(f"C-Number: {student_c_number}")
print(f"Enrollment Year: {enrollment_year}")
grader.check("q1_student_identity")
Part 2: Height Processing¶
International students often provide height in centimeters, while US students use feet and inches. The database needs both formats, so we need to convert between them.
Question 2: Inches to Centimeters (1 point)¶
A student's height is provided in inches. Convert it to centimeters.
Conversion: 1 inch = 2.54 centimeters
Task:
- Use the
height_inchesvariable (already provided below) - Calculate the height in centimeters
- Store the result in a variable named exactly
height_cm
# Student's height from their form (in inches)
height_inches = 68
# ✏️ YOUR CODE: Convert to centimeters
# Store the result in a variable named exactly: height_cm
height_cm = ...
print(f"{height_inches} inches = {height_cm} cm")
grader.check("q2_inches_to_cm")
Question 3: Feet and Inches to Total Inches (1 point)¶
Some registration forms have separate fields for feet and inches. We need to calculate the total height in inches first.
Conversion: 1 foot = 12 inches
Task:
- Use
height_feetandheight_extra_inches(provided below) - Calculate the total height in inches
- Store the result in a variable named exactly
total_height_inches
Example: Someone who is 5 feet 8 inches tall is 5×12 + 8 = 68 inches total.
# Student entered their height as feet and inches separately
height_feet = 5
height_extra_inches = 8 # Note: this is the EXTRA inches beyond the feet, not total
# ✏️ YOUR CODE: Calculate TOTAL inches
# Store the result in a variable named exactly: total_height_inches
total_height_inches = ...
print(
f"{height_feet} feet {height_extra_inches} inches = {total_height_inches} total inches"
)
grader.check("q3_feet_inches_to_total")
Part 3: Weight Processing¶
The student health center needs weight in kilograms for medical dosage calculations, but most US students provide weight in pounds.
Question 4: Pounds to Kilograms (1 point)¶
Convert a student's weight from pounds to kilograms.
Conversion: 1 kilogram = 2.205 pounds (so divide pounds by 2.205 to get kg)
Task:
- Use
weight_lbs(provided below) - Convert to kilograms
- Round to 1 decimal place using
round(value, 1) - Store the result in a variable named exactly
weight_kg
# Weight from student health form (in pounds)
weight_lbs = 165
# ✏️ YOUR CODE: Convert to kilograms, rounded to 1 decimal place
# Store the result in a variable named exactly: weight_kg
# Hint: Use round(value, 1) to round to 1 decimal place
weight_kg = ...
print(f"{weight_lbs} lbs = {weight_kg} kg")
grader.check("q4_lbs_to_kg")
Part 4: Age Calculation¶
The system needs to calculate a student's age and determine if they're eligible for certain services (which require being 18 or older).
Question 5: Age Calculation (2 points)¶
Calculate a student's age from their birth year and determine if they're an adult.
Task:
- Calculate the student's age (current year minus birth year)
- Store it in a variable named exactly
student_age - Determine if the student is an adult (18 or older)
- Store the result as a boolean (
TrueorFalse) in a variable named exactlyis_adult
Important: is_adult must be True or False (no quotes!), not the strings "True" or "False".
# From the registration form
birth_year = 2005
current_year = 2026
# ✏️ YOUR CODE: Calculate age and adult status
# Create variable: student_age (integer)
# Create variable: is_adult (boolean - True if 18 or older, False otherwise)
student_age = ...
is_adult = ...
print(f"Age: {student_age}")
print(f"Is adult (18+): {is_adult}")
grader.check("q5_age_calculation")
Question 6: Temperature Conversion (1 point)¶
The student health center records body temperatures during check-ups. They use Fahrenheit, but international medical records use Celsius.
Formula: Celsius = (Fahrenheit - 32) × 5/9
Task:
- Use
temp_fahrenheit(provided below) - Convert to Celsius using the formula above
- Round to 1 decimal place
- Store the result in a variable named exactly
temp_celsius
Watch out: Order of operations matters! Subtract 32 first, then multiply by 5/9.
# Body temperature from health screening (Fahrenheit)
temp_fahrenheit = 98.6
# ✏️ YOUR CODE: Convert to Celsius, rounded to 1 decimal place
# Store the result in a variable named exactly: temp_celsius
# Formula: C = (F - 32) × 5/9
temp_celsius = ...
print(f"{temp_fahrenheit}°F = {temp_celsius}°C")
grader.check("q6_temperature")
Part 5: Profile Assembly¶
Time to bring everything together! You'll create a formatted profile output that combines all the data you've processed.
Question 7: Complete Profile Output (2 points)¶
Create a formatted string containing the complete student profile.
Your output must match this EXACT format:
===== CANE CARD PROFILE =====
Name: [First] [Last]
C-Number: [C-Number]
Enrollment Year: [Year]
Height: [inches] in ([cm] cm)
Weight: [lbs] lbs ([kg] kg)
Age: [age] (Adult: [Yes/No])
Temperature: [F]°F ([C]°C)
=============================
Requirements:
- Store the complete formatted string in a variable named exactly
profile_output - Use variables from previous questions (this cell depends on earlier cells!)
- Adult status should display as "Yes" or "No", not True/False
- Include the header and footer lines with
=signs - Use
\nfor newlines inside your f-string
Hint: For Yes/No, you can use: "Yes" if is_adult else "No"
# ✏️ YOUR CODE: Build the complete profile string
# Use the variables you created in previous questions
# Store the result in: profile_output
#
# IMPORTANT: The adult status should show "Yes" or "No", not True or False
# Hint: You can use a conditional expression: "Yes" if is_adult else "No"
adult_status = ...
profile_output = ...
...
...
...
...
...
...
...
...
...
print(profile_output)
grader.check("q7_profile_output")
Stretch Goal: Enhanced Age Calculation¶
The simple age calculation (current year - birth year) isn't quite accurate. It doesn't account for whether the student has had their birthday yet this year.
This is a bonus question for extra credit!
Question 8: Enhanced Age Calculation - STRETCH GOAL (1 bonus point)¶
Calculate a more accurate age that accounts for whether the birthday has passed.
Logic:
- If the current month is before the birth month → the person hasn't had their birthday yet → subtract 1 from the simple age
- If the current month is equal to or after the birth month → use the simple age
Task:
- Use the provided variables:
birth_year,birth_month,current_year,current_month - Calculate the accurate age
- Store the result in a variable named exactly
accurate_age
Hint: You can use a conditional expression:
value_if_true if condition else value_if_false
# More detailed birth information
q8_birth_year = 2005
q8_birth_month = 9 # September
q8_current_year = 2026
q8_current_month = 1 # January (current)
# ✏️ YOUR CODE: Calculate accurate age
# If we haven't reached their birth month yet this year, they're one year younger
# Store the result in: accurate_age
simple_age = ...
accurate_age = ...
print(f"Birth: {q8_birth_month}/{q8_birth_year}")
print(f"Current: {q8_current_month}/{q8_current_year}")
print(f"Simple age: {q8_current_year - q8_birth_year}")
print(f"Accurate age: {accurate_age}")
grader.check("q8_accurate_age")
Summary¶
Congratulations! You've built a complete student registration data processor. Here's what you accomplished:
| Task | What You Learned |
|---|---|
| Student Identity | Creating variables with specific names and types |
| Height Conversion | Mathematical operations and unit conversions |
| Weight Conversion | Division and rounding with round() |
| Age Calculation | Subtraction and boolean comparisons |
| Temperature Conversion | Order of operations in formulas |
| Profile Assembly | f-strings, string formatting, conditional expressions |
Key Takeaways¶
- Variable names matter - Use descriptive names and be consistent
- Types matter - Numbers without quotes, strings with quotes, booleans are
True/False - Order of operations matters - Use parentheses to control calculation order
- f-strings are powerful - They let you embed variables directly in text
You have completed the Cane Card Registration System lab!
To double-check your work, the cell below will rerun all of the autograder tests.
grader.check_all()