Skip to content
My Python workspace
# Add your Python code here!
import numpy as np
import numpy.random as random
balance = 1000
def roulette():
number = random.randint(0,37,1)
if (number == 0):
colour = "Green"
elif (number == 1 or number == 3 or number == 5 or number == 7 or number == 9 or number == 12 or number == 14 or number == 16 or number == 18 or number == 19 or number == 21 or number == 23 or number == 25 or number == 27 or number == 30 or number == 32 or number == 34 or number == 36):
colour = "Red"
else:
colour = "Black"
return number, colour
def placebet(betcolour, amount):
number, colour = roulette()
global balance
if (colour == betcolour):
#print("You won", amount)
balance += amount
#print("Your balance is now", balance)
outcome = "Win"
else:
#print("You lose", amount)
balance -= amount
#print("Your balance is now", balance)
outcome = "Loss"
return outcome
def simulate(betsize):
global balance
balance = 1000
while True:
##print("--")
if betsize > balance:
betsize = balance
outcome = placebet("Red", betsize)
if (outcome == "Win"):
betsize = 50
elif(outcome == "Loss" and balance < 1000):
if(betsize * 2 < balance):
betsize = betsize * 2
if (balance <=0):
break
if (balance >=1500):
break
return balance
def simulations(numberofsim):
outcomearr = []
i = 0
for i in range(numberofsim):
outcomearr.append(simulate(50))
return outcomearr
x = simulations(100000)
import statistics
i = 0
timeswon = 0
timeslost = 0
for i in range (len(x)):
if x[i] == 0:
timeslost += 1
if x[i] == 1500:
timeswon += 1
i += 1
percentagewon = timeswon / 100000
print("Percentage of times you win 500 euros after 100000 simulations:", round(100*percentagewon, 2), "%")
print("Percentage of times you lose 1000 euros after 100000 simulations:",round(100*(1 - percentagewon), 2), "%") x = simulations(10000)
import statistics
i = 0
timeswon = 0
timeslost = 0
for i in range (len(x)):
if x[i] == 0:
timeslost += 1
if x[i] == 1060:
timeswon += 1
i += 1
percentagewon = timeswon / 10000
print("Percentage of times you win 50 euros after 10000 simulations:", round(100*percentagewon, 2), "%")
print("Percentage of times you lose 1000 euros after 10000 simulations:",round(100*(1 - percentagewon), 2), "%")
simulate(20)i=0
for i in range(5):
print(i)
i+=1
DataFrameas
df
variable
-- Select the product details, quantity, and location of bicycles in stock
SELECT product_name,
category_name,
list_price,
SUM(quantity) AS total_quantity,
store_id
FROM products
INNER JOIN stocks
ON products.product_id = stocks.product_id
INNER JOIN categories
ON products.category_id = categories.category_id
WHERE list_price <= 3000
GROUP BY product_name, category_name, list_price, store_id
ORDER BY list_price DESCCurrent Type: Bar
Current X-axis: index
Current Y-axis: list_price
Current Color: None