Popcorn hack2
# Popcorn Hack Number 2 (Random): Make a random algorithm to choose a daily activity:
import random
# Step 1: Define a list of activities
activities = ['dog walk', ' Watch a show', 'Call a family', 'cook', 'watch a movie', 'go to bed', 'workout', 'Write a story', 'do yoga', 'Listen to music', 'Do anything but homework']
# Step 2: Randomly choose an activity
random_activity = random.choice(activities)
# Step 3: Display the chosen activity
print(f"Today’s random activity: {random_activity}")
Today’s random activity: Write a story
Popcorn Hack 3
import random
hosts = ['Gavin', 'Johan', 'Jacob', 'Elliot']
activities = ['dancing', 'games', 'snack center', 'photo booth', 'karaoke', 'take a selfie', ]
# Randomly shuffle the list of activities to assign them randomly to the guests
random.shuffle(activities)
# Loop through each guest and assign them a random activity
for i in range(len(hosts)):
print(f"{hosts[i]} will be monitoring {activities[i]}!")
Gavin will be monitoring games!
Johan will be monitoring karaoke!
Jacob will be monitoring photo booth!
Elliot will be monitoring dancing!
Popcorn Hack 1
import random
def spin_number():
return random.randint(1, 10) # You can change 1 and 10 to whatever range you want
spin_result = spin_number()
print("Spinner landed on:", spin_result)
Spinner landed on: 6
Popcorn Hack 2
import random
def play_rock_paper_scissors():
choices = ['rock', 'paper', 'scissors']
computer_choice = random.choice(choices)
user_choice = input("Enter your choice (rock, paper, or scissors): ")
if user_choice not in choices:
print("Invalid choice. Please try again.")
return
print("Computer chose:", computer_choice)
print("You chose:", user_choice)
if user_choice == computer_choice:
print("It's a tie!")
elif (user_choice == 'rock' and computer_choice == 'scissors') or \
(user_choice == 'paper' and computer_choice == 'rock') or \
(user_choice == 'scissors' and computer_choice == 'paper'):
print("You win!")
else:
print("You lose!")
play_rock_paper_scissors()
Computer chose: rock
You chose: rock
It's a tie!
Homework hack 1
import random
students = [
"Alice", "Ben", "Carla", "Daniel", "Eva",
"Felix", "Grace", "Hannah", "Isaac", "Jade",
"Kyle", "Luna", "Marcus", "Nina", "Oscar"
]
teams = ["Team Phoenix", "Team Dragon", "Team Titan"]
assignments = {}
for student in students:
team = random.choice(teams)
assignments[student] = team
for student, team in assignments.items():
print(f"{student} → {team}")
Alice → Team Phoenix
Ben → Team Phoenix
Carla → Team Phoenix
Daniel → Team Titan
Eva → Team Phoenix
Felix → Team Dragon
Grace → Team Titan
Hannah → Team Phoenix
Isaac → Team Dragon
Jade → Team Phoenix
Kyle → Team Phoenix
Luna → Team Titan
Marcus → Team Dragon
Nina → Team Titan
Oscar → Team Dragon
Homework Hack 2
import random
weather_types = ["Sunny", "Cloudy", "Rainy"]
forecast = []
for day in range(1, 8):
weather = random.choice(weather_types)
forecast.append(weather)
print(f"Day {day}: {weather}")
Day 1: Sunny
Day 2: Sunny
Day 3: Sunny
Day 4: Sunny
Day 5: Sunny
Day 6: Sunny
Day 7: Sunny
Homework Hack 3
import random
customers = ["Customer 1", "Customer 2", "Customer 3", "Customer 4", "Customer 5"]
total_time = 0
for customer in customers:
service_time = random.randint(1, 5)
total_time += service_time
print(f"{customer} - Served in {service_time} minutes")
print("\nTotal time to serve all customers:", total_time, "minutes")
Customer 1 - Served in 1 minutes
Customer 2 - Served in 1 minutes
Customer 3 - Served in 1 minutes
Customer 4 - Served in 3 minutes
Customer 5 - Served in 2 minutes
Total time to serve all customers: 8 minutes