Hi All
For some of you html/Css is a new concept for others its something you have done previously.
To lessons below.
Scratch Option
poetry-generator
MicroBit
reaction
Hi All
For some of you html/Css is a new concept for others its something you have done previously.
To lessons below.
Scratch Option
poetry-generator
MicroBit
reaction
Today we are going to construct a small game using the micro-bit which using an idea below.
https://en.wikipedia.org/wiki/Monty_Hall_problem
Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?
Vos Savant’s response was that the contestant should switch to the other door (vos Savant 1990a). Under the standard assumptions, contestants who switch have a 2/3 chance of winning the car, while contestants who stick to their initial choice have only a 1/3 chance.
So we are going to create a game based on the above theory to prove it right or wrong.
List Prizes
Strings
Goat
Car
Goat
prizes = ["Goat","Goat","Car"] print(prizes[0])
from random import shuffle from random import randint
shuffle(prizes)
from random import shuffle from random import randint prizes = ["Goat","Goat","Car"] shuffle(prizes) print(prizes[0])
print("Monty: Please select a door between 0 and 2")
door = input()
print("Monty: You Selected door number "+door)
from random import shuffle
from random import randint
prizes = ["Goat","Goat","Car"]
shuffle(prizes)
print("Monty: Please select a door between 0 and 2")
door = input()
print("Monty: You Selected door number "+door)
def convertStr(s):
try:
ret = int(s)
except ValueError:
ret = float(s)
return ret
from random import shuffle
from random import randint
def convertStr(s):
try:
ret = int(s)
except ValueError:
ret = float(s)
return ret
prizes = ["Goat","Goat","Car"]
shuffle(prizes)
print("Monty: Please select a door between 0 and 2")
door = input()
print("Monty: You Selected door number "+door)
selected_door_int = convertStr(door)
print("MONTY: I will now select a door")
presenter_door = randint(0,2)
while 1:
if presenter_door != selected_door_int or prizes[presenter_door] != "Car":
presenter_door = randint(0,2)
break
print("MONTY: I selected door number "+str(presenter_door)+" and my prize was a "+prizes[presenter_door]);
from random import shuffle
from random import randint
def convertStr(s):
try:
ret = int(s)
except ValueError:
ret = float(s)
return ret
prizes = ["Goat","Goat","Car"]
shuffle(prizes)
print("MONTY: Please select a door between 0 and 2")
door = input()
print("You Selected door number "+door)
selected_door_int = convertStr(door)
print("MONTY:I will now select a door")
presenter_door = randint(0,2)
while 1:
if presenter_door == selected_door_int or prizes[presenter_door] == "Car":
presenter_door = randint(0,2)
break
print("I selected door number "+str(presenter_door)+" and my prize was a "+prizes[presenter_door]);
print("MONTY: Do you want to change you're mind on you're door type Yes Or No?")
answer = input()
print("MONTY: You selected "+answer)
if answer.lower() == "no":
print("You have won a "+prizes[selected_door_int])
else:
final_door = randint(0,2)
while 1:
if final_door == selected_door_int or presenter_door == final_door:
final_door = randint(0,2)
break
print("You have won a "+prizes[final_door])
from random import shuffle
from random import randint
def convertStr(s):
try:
ret = int(s)
except ValueError:
ret = float(s)
return ret
prizes = ["Goat","Goat","Car"]
shuffle(prizes)
print("MONTY: Please select a door between 0 and 2")
door = input()
print("You Selected door number "+door)
selected_door_int = convertStr(door)
print("MONTY:I will now select a door")
presenter_door = randint(0,2)
while 1:
if presenter_door == selected_door_int or prizes[presenter_door] == "Car":
presenter_door = randint(0,2)
break
print("MONTY: I selected door number "+str(presenter_door)+" and my prize was a "+prizes[presenter_door]);
print("MONTY: Do you want to change you're mind on you're door type Yes Or No?")
answer = input()
print("MONTY: You selected "+answer)
if answer.lower() == "no":
print("You have won a "+prizes[selected_door_int])
else:
final_door = randint(0,2)
while 1:
if final_door == selected_door_int or presenter_door == final_door:
final_door = randint(0,2)
break
print("You have won a "+prizes[final_door])
# Add your Python code here. E.g.
from microbit import *
while True:
display.scroll('Hello, World!')
display.show(Image.HEART)
sleep(2000)
# Add your Python code here. E.g.
from microbit import *
import random
prizes = ["Goat","Goat","Car"]
door = 0
while True:
display.scroll('MONTY: Please select a door')
display.clear()
if button_a.get_presses() or button_b.get_presses():
door = random.randint(0,2)
display.clear()
text = "Monty: You Selected door number "+str(door)
display.scroll(text)
display.clear()
display.scroll("Monty: I will now select a door")
presenter_door = random.randint(0,2)
while 1:
if presenter_door == door or prizes[presenter_door] == "Car":
presenter_door = random.randint(0,2)
break
display.scroll("MONTY: I selected door number "+str(presenter_door)+" and my prize was a "+prizes[presenter_door])
display.clear()
display.scroll("MONTY: Do you want to change you're mind on you're door type Yes(a) Or No(b)?")
if button_a.get_presses():
final_door = random.randint(0,2)
while 1:
if final_door == door or presenter_door == final_door:
final_door = random.randint(0,2)
break
display.scroll("You have won a "+prizes[final_door])
elif button_b.get_presses():
display.scroll("You have won a "+prizes[door])