Sprint 2 - Random Numbers! (Python)
Homework in Random Numbers in Python
- ๐ Homeworks & Creative Tasks (Python, Pick 1)
- โจ Task 1: Simple Loot Box
- ๐ฒ Task 2: Dice Rolling Counter
- ๐ Task 3: Random Story Generator
- โ๏ธ Task 4: Basic Fairness Test
๐ Homeworks & Creative Tasks (Python, Pick 1)
โจ Task 1: Simple Loot Box
Create a basic program that opens 10 loot boxes. Use a slider to change the chance of getting rare items (10% to 90%). Count how many common vs rare items you get. Display the results in a simple list.
๐ฒ Task 2: Dice Rolling Counter
Roll a 6-sided die 20 times. Keep track of how many times each number (1โ6) appears. Show the counts in a simple chart or list. Students can see if numbers appear evenly or not.
๐ Task 3: Random Story Generator
Pick random words from simple lists (character, place, action). Example: "The [knight/wizard/dragon] went to the [castle/forest/cave] and [fought/slept/ate]". Generate 5 random stories with one button click. Show all stories in a list.
โ๏ธ Task 4: Basic Fairness Test
Roll a die 100 times. Count how many times each number appears. Check if each number appears around 16โ17 times (100 รท 6 โ 16.67). Display results: "Fair!" if numbers are close to 16โ17, "Maybe unfair?" if very different.
All tasks should use simple JavaScript with Math.random()
and basic HTML buttons and displays. No complex statistics or advanced libraries are needed.
import random
# Number of rolls
num_rolls = 20
# Make a dictionary to count each number
counts = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
# Roll the dice 20 times
for i in range(num_rolls):
roll = random.randint(1, 6)
counts[roll] += 1
# Print the result
print("๐ฒ Dice Rolling Counter (20 Rolls)")
for number in range(1, 7):
print(f"Number {number}: {counts[number]} times")
๐ฒ Dice Rolling Counter (20 Rolls)
Number 1: 3 times
Number 2: 6 times
Number 3: 4 times
Number 4: 3 times
Number 5: 3 times
Number 6: 1 times