This page contains codes and little programs I’ve made
Random numbers
i = 0
# numNames = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"]
# Revision:
numNames = "Zero One Two Three Four Five Six Seven Eight Nine Ten".split() # Works exactly the same as the commented code above
numbers = [0,0,0,0,0,0,0,0,0,0,0]
while (i < 10000):
randNum = round(Random.random() * 10)
numbers[randNum] += 1
i += 1
i = 0
total = 0
most = 0
mostRolls = 0
while (i <= 10):
print(f"{numNames[i]}: {numbers[i]}")
total += numbers[i]
if numbers[i] > mostRolls:
mostRolls = numbers[i]
most = i
i += 1
print(f"And the total adds up to {total}! The number that was 'rolled' most was {numNames[most]} with {numbers[most]} rolls!")
How long would it take to make a coin land on heads 10 times in a row?
Let’s say 1 is heads, and 2 is tails. And let’s say that one toss takes 7 seconds.
This program uses the secsToDHM function.
heads = 0; tosses = 0
while(heads < 10):
toss = Random.randint(1,2)
if toss == 1:
heads += 1
else:
heads = 0
tosses += 1
print(f"It took {tosses} tosses ({secsToDHM(7 * tosses)})")
# How many spins does it take on a roulette wheel to hit zero X times in a row?
# We'll go with 30 seconds per spin for this one
spins = 0; green = 0
while(green < 4):
spins += 1
spin = Random.randint(1,37) # 37 is green
if spin == 37: green += 1
else: green = 0
print(f"It took {spins} spins to hit green 4 times in a row ({secsToDHM(30 * spins)})")
Leave a Reply