Skip to the content.

3.9-3.15 Popcorn Hacks

My answers for the popcorn hacks

CSP Big Idea 3.9-3.15

Popcorn Hack #1

# Popcorn Hack Number 2 (Random): Make a random algorithm to choose a daily activity:
import random
# Step 1: Define a list of activities
activities = ['Go for a walk', 'Read a book', 'lock in', 'Cook', 'Watch minecraft movie', 'Play Guitar', 'Go for a run', 'Write in a journal', 'Meditate', 'Listen to music', 'Be productive and do your 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: Be productive and do your homework

Popcorn Hack #2

You and your team are hosting a party. With your team, make a random algorithm to help them decide which person should monitor which activity. Copy and Paste this code into a Python cell in your jupyter notebook, change the names and types of activities, and see which gets chosen.

# Popcorn Hack Number 3: Using a loops in random
# This popcorn hack assigns an activity to each person
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 snack center!
Johan will be monitoring take a selfie!
Jacob will be monitoring dancing!
Elliot will be monitoring photo booth!

Popcorn Hack #3

Instead of a dice roll, this time let’s create a number spinner. Use the set up of the dice roll example to simulate a number spinner. Create whatever range of numbers you want and share your range and output with the class when finished!

import random

def roll_dice():
    return random.randint(1, 50)

dice_roll = roll_dice()
print("Number:", dice_roll)
Number: 12

Rock Paper Scissors activity

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: paper
You chose: scissors
You win!