Technology has failed campus-wide! Use Python programming and computational thinking to save the day!
The university is in crisis! All computer systems at Chaotic University have mysteriously crashed overnight!
Classes start tomorrow and everyone is in a panic!
Crisis: Student rosters are scrambled across classes!
Help organize attendance lists and grade data before tomorrow's classes.
Crisis: Enrollment system crashed during registration!
Process hundreds of pending applications and create organized student records.
Crisis: Lab data from multiple experiments is mixed up!
Sort and analyze research data to save months of work.
Crisis: User accounts and permissions are chaos!
Automate user management and fix access control systems.
Welcome to your role! You need to learn Python to solve real university problems.
Python is a popular programming language with easy-to-read syntax. Let's start with the basics!
A variable in Python is like a labeled container that holds information.
We define a variable using this pattern: variable_name = value
Important: Text must have quotes around it, but numbers don't need quotes.
Examples:
name = "Sarah"
โ Text needs quotes
age = 25
โ Numbers don't need quotes
is_student = True
โ True/False don't need quotes
# Employee review data
employee_name = "Sarah Chen"
review_score = 4.2
is_promotion_eligible = True
department_list = ["Engineering", "Marketing", "Sales", "HR"]
employee_name โ "Sarah Chen"
review_score โ 4.2
is_promotion_eligible โ True
department_list โ ["Engineering", "Marketing", "Sales", "HR"]
Create a variable that stores the name of your favorite programming language (hint: it should be "Python"!)
You need to organize different types of university data efficiently.
Different types of data require different data types:
Python has five main data types you need to know:
int = whole numbers (like 25, 100, -5)
float = decimal numbers (like 3.14, 98.6, -2.5)
str = text (always needs quotes: "Hello", "Python")
bool = True or False (no quotes needed)
list = collection of items (uses square brackets [ ])
# Different data types for different purposes
# Essential Python data types
student_id = 12847 # int (integer) - for whole numbers
name = "Aisha Patel" # str (string) - for text
gpa = 3.85 # float - for decimal numbers
is_enrolled = True # bool (boolean) - for True/False
courses = ["CS101", "MATH201"] # list - for collections of items
print(f"ID: {student_id}")
print(f"Name: {name}")
print(f"GPA: {gpa}")
print(f"Enrolled: {is_enrolled}")
print(f"Courses: {courses}")
ID: 12847
Name: Aisha Patel
GPA: 3.85
Enrolled: True
Courses: ['CS101', 'MATH201']
Create an interactive system for your university role.
The input() functionwaits for the user to type in their input. It does not proceed until the enter key is pressed.
# Getting input from users
student_name = input("Enter student name: ")
credit_hours = int(input("Total credit hours completed: "))
# Processing and displaying results
if credit_hours < 30:
status = "Freshman"
elif credit_hours < 60:
status = "Sophomore"
elif credit_hours < 90:
status = "Junior"
else:
status = "Senior"
print(f"\n{student_name}'s status: {status}")
Enter student name: Amara Johnson
Total credit hours completed: 30
Amara Johnson's status: Sophomore
An f-string (formatted string) is a way to format text by including variables inside it. Let's see the difference:
Without f-string (harder way):
print("Hello, " + name + "!")
With f-string (easier way):
print(f"Hello, {name}!")
F-strings use curly braces {}
to include variables inside the text.
The variable, student_name
, stores a student's name.
Complete this f-string to display the student's name: print(f"Hello, ____")
Remember: F-strings use curly braces {} to include variables!
The input()
function always stores the user's input as text, even if they type a number!
Problem: age = input("Your age: ")
โ age is text like "25"
Solution: Convert text to numbers using:
int()
= converts to whole numbers
float()
= converts to decimal numbers
Example: age = int(input("Your age: "))
# Getting numbers from users
years_text = input("Years of experience: ") # This is text: "5"
years_number = int(years_text) # Convert to integer: 5
# Or do it in one step (more common)
years_experience = int(input("Years of experience: "))
current_salary = float(input("Current salary: ")) # float for decimals
Years of experience: 5
Current salary: 65000.50
Now you can do math with these numbers!
Organize multiple pieces of related data efficiently.
Lists can hold collections of data. Python uses zero-based indexing!
# Creating and managing lists
students = ["Aisha", "Carlos", "Amara", "Diane"]
grades = [95, 87, 92, 88]
print("Class Roster:")
for i in range(len(students)):
print(f"{i+1}. {students[i]} - Grade: {grades[i]}")
# Adding new student
students.append("Eve")
grades.append(94)
print(f"\nTotal students: {len(students)}")
print(f"Average grade: {sum(grades)/len(grades):.1f}")
Class Roster:
1. Aisha - Grade: 95
2. Carlos - Grade: 87
3. Amara - Grade: 92
4. Diane - Grade: 88
Total students: 5
Average grade: 91.2
Create a list containing three of your favorite subjects:
Python has built-in functions that help you work with lists more effectively:
# Useful list functions
grades = [95, 87, 92, 88, 94]
students = ["Carlos", "Eve", "Diane", "Jamal", "Sofia"]
# len() tells you how many items are in a list
total_students = len(students)
total_grades = len(grades)
# sum() adds up all numbers in a list
total_points = sum(grades)
# Calculate average
average_grade = sum(grades) / len(grades)
print(f"Total students: {total_students}")
print(f"Total points: {total_points}")
print(f"Average grade: {average_grade:.1f}")
# You can also use len() to check if a list is empty
if len(students) > 0:
print("We have students!")
else:
print("No students yet.")
Total students: 5
Total points: 456
Average grade: 91.2
We have students!
You have a list of test scores: test_scores = [85, 92, 78, 96, 89]
. What function would you use to find how many scores there are?
The split() method is very useful for processing data. It breaks a string into a list based on a separator.
The split()
method turns a string into a list by breaking it apart:
Example:
data = "Alice,25,Engineer"
parts = data.split(",")
Result: ["Alice", "25", "Engineer"]
The comma tells split() where to break the string apart!
# Processing employee data with split()
employee_data = "John Smith,30,Manager,75000"
# Split by commas to get individual pieces
info = employee_data.split(",")
name = info[0] # "John Smith"
age = int(info[1]) # 30 (converted to number)
position = info[2] # "Manager"
salary = int(info[3]) # 75000 (converted to number)
print(f"Employee: {name}")
print(f"Position: {position}")
print(f"Salary: ${salary:,}")
Employee: John Smith
Position: Manager
Salary: $75,000
You have a string variable named subjects
that stores the string "Math,Science,History"
. What would you write to split it into a list of subjects?
Create automated decision-making systems for your university role.
Boolean logic allows programs to make decisions based on conditions.
# Automated student evaluation
students = [
{"name": "Aisha", "grade": 95, "attendance": 0.98},
{"name": "Carlos", "grade": 72, "attendance": 0.85},
{"name": "Diane", "grade": 88, "attendance": 0.92}
]
for student in students:
name = student["name"]
grade = student["grade"]
attendance = student["attendance"]
print(f"\nEvaluating {name}:")
print(f" Grade: {grade}")
print(f" Attendance: {attendance:.0%}")
if grade >= 90 and attendance >= 0.95:
status = "Dean's List"
elif grade >= 70 and attendance >= 0.80:
status = "Passing"
else:
status = "Needs Improvement"
print(f" Status: {status}")
Evaluating Aisha:
Grade: 95
Attendance: 98%
Status: Dean's List
Evaluating Carlos:
Grade: 72
Attendance: 85%
Status: Passing
Evaluating Diane:
Grade: 88
Attendance: 92%
Status: Passing
Write an if statement to check if a score is passing (>= 70):
Time to put all your skills together!