Skip to the content.

Binary Search Algorithms

None

None

Popcorn Hack 2

# Popcorn Hack Number 2 (Random): Make a random algorithm to choose a daily activity:
import random
# Step 1: Define a list of activities
activities = ['Play Brawl Stars', 'Do Homework', 'Talk to Friends', 'Discuss the Geo-Political State of the World', 'Play Deepwoken', 'Study for AP exams', 'Watch TV', 'Play other video games']
# 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: Play other video games

Popcorn Hack 3

# Popcorn Hack Number 3: Using a loops in random
# This popcorn hack assigns an activity to each person
import random
hosts = ['Arnav', 'Ahaan', 'Weston']
activities = ['code, code, code', 'games', 'bean bag toss', 'movies']
# 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]}!")
Arnav will be monitoring games!
Ahaan will be monitoring bean bag toss!
Weston will be monitoring movies!

Popcorn Hack 1

import random

def number_spinner():
    return random.randint(1, 100)

number = number_spinner()
print(f"Number: {number}")
Number: 48

Popcorn Hack 2

I won against Ahaan (because of course I did)

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

MCQ Answers

  • C (first output cannot be because i is initially 2 and 1 is added after first output)
  • D (75 % chance so 1-75 in order to mimic that chance in the simulation)
  • C (cutting out data would make it less accurate)
  • D (the predator variable isn’t changed after it is created, only used to change the numMice variable)

Homework Hack 1

students = ['Arnav', 'Ahaan', 'Weston', 'Manas', 'Ahmed', 'Arhaan', 'Rutvik', 'Mihir', 'Gyutae', 'Rayhaan', 'Risha', 'Ameya', 'Arnav (P)', 'Xavier', 'Harshit' ]

team_perros_y_gatos = []
team_burrito_bandits = []
team_i_was_feeling_a_lil_spanish = []

for x in range (len(students)):
    y = random.randrange(0, 3)
    if y == 0:
        team_perros_y_gatos.append(students[x])
    elif y == 1:
        team_burrito_bandits.append(students[x])
    else:
        team_i_was_feeling_a_lil_spanish.append(students[x])

print(students)
print("Team Perros y Gatos:", team_perros_y_gatos)
print("Team Burrito Bandits:", team_burrito_bandits)
print("Team I Was Feeling a Lil Spanish:", team_i_was_feeling_a_lil_spanish)
['Arnav', 'Ahaan', 'Weston', 'Manas', 'Ahmed', 'Arhaan', 'Rutvik', 'Mihir', 'Gyutae', 'Rayhaan', 'Risha', 'Ameya', 'Arnav (P)', 'Xavier', 'Harshit']
Team Perros y Gatos: ['Arnav', 'Ahmed', 'Arhaan', 'Mihir', 'Ameya', 'Harshit']
Team Burrito Bandits: ['Ahaan', 'Rutvik', 'Gyutae', 'Arnav (P)']
Team I Was Feeling a Lil Spanish: ['Weston', 'Manas', 'Rayhaan', 'Risha', 'Xavier']

Homework Hack 2

weather_options = ['sunny', 'rainy', 'cloudy']

for weather in range(7):
    weather_today = random.choice(weather_options)
    print(f"Weather for day {weather + 1}: {weather_today}")
Weather for day 1: cloudy
Weather for day 2: sunny
Weather for day 3: cloudy
Weather for day 4: sunny
Weather for day 5: rainy
Weather for day 6: cloudy
Weather for day 7: rainy

Homework Hack 3

total_time = 0

for x in range(5):
    time = random.randint(1, 5)
    total_time += time
    print(f"It took {time} minutes to serve customer {x + 1}")

print(f"Total time taken to serve all 5 customers: {total_time} minutes")

It took 2 minutes to serve customer 1
It took 3 minutes to serve customer 2
It took 5 minutes to serve customer 3
It took 4 minutes to serve customer 4
It took 2 minutes to serve customer 5
Total time taken to serve all 5 customers: 16 minutes