Homework Hack #1
Objective: Randomly assign students to teams for a group project.
Task:
You are given a list of 15 students. The goal is to randomly assign each student to one of 3 teams (be creative with the names) Implement the random assignment: Randomly assign each student to a team Print out the list of students and their assigned teams.
# Popcorn Hack Number 3: Using a loops in random
# This popcorn hack assigns an activity to each person
import random
groups = ['code code coders', 'Purple Pythons', 'Mending Miners']
students = ['Yuno Miles','Playboi Carti', 'Travis Scott', 'Kanye West', 'Kendrick Lamar', 'Drake', 'J.Cole', 'JID', 'Lil Uzi Vert', 'Lil Baby', '21 Savage', 'Tyler the Creator', 'Lil Wayne', 'A$AP Rocky', 'Post Malone']
# Randomly shuffle the list of activities to assign them randomly to the guests
random.shuffle(students)
group_assignments = {group: [] for group in groups}
# Assign 5 students to each group
for i in range(len(students)):
group = groups[i // 5] # Integer division ensures 5 per group
group_assignments[group].append(students[i])
for group, members in group_assignments.items():
print(f"\n{group}:")
for member in members:
print(f" - {member}")
code code coders:
- Yuno Miles
- Post Malone
- Tyler the Creator
- Drake
- Lil Wayne
Purple Pythons:
- JID
- Lil Baby
- Kanye West
- Kendrick Lamar
- 21 Savage
Mending Miners:
- Lil Uzi Vert
- A$AP Rocky
- Playboi Carti
- J.Cole
- Travis Scott
Homework Hack #2
import random
weather = ['cloudy', 'rainy', 'sunny', 'windy', 'stormy']
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
for day in days:
forecast = random.choice(weather)
print(f"{day} will be {forecast}!")
Monday will be cloudy!
Tuesday will be cloudy!
Wednesday will be windy!
Thursday will be windy!
Friday will be sunny!
Saturday will be windy!
Sunday will be cloudy!
Homework Hack #3
Objective: Simulate a random coffee shop queue and determine how long it takes for customers to get served.
Task: Simulate a coffee shop with 5 customers. Each customer has a random service time (between 1 and 5 minutes). The coffee shop serves customers in the order they arrive. Calculate and print the total time it takes for all 5 customers to be served.
import random
customers = ['Bob', 'Bobby', 'Borb', 'Beb', 'Bab']
total_time = 0
print("Coffee Shop Queue Simulation:")
for customer in customers:
service_time = random.randint(1, 5)
total_time += service_time
print(f"{customer} was served in {service_time} minutes.")
print(f"\nTotal time to serve all customers: {total_time} minutes.")
Coffee Shop Queue Simulation:
Bob was served in 2 minutes.
Bobby was served in 1 minutes.
Borb was served in 2 minutes.
Beb was served in 1 minutes.
Bab was served in 2 minutes.
Total time to serve all customers: 8 minutes.