Write a program to simulate the Door game . Make a program that has the output as the following:
Hello, welcome to our program! Let's see if you will win a car or not! Choose a door: 3 You chose Door 3, but I inform you that at Gate 2 there is a goat. Do you want to switch ports (1 - Yes / 0 - No): 1 You won a car!
My solution:
import random #selecionar a porta
testes = int(input("Digite o número de testes: "))
bode =0
trocar =0 #nao trocar
for i in range(testes):
porta = random.randrange(1,4) #portas de 1 a 3
premio = random.randint(1,3) #randint inclui o extremo!
bode = random.randint(1,3)
if premio != bode and premio !=porta:
print("A porta {} tem um bode. ".format(bode))
trocar = int(input("Deseja trocar? "))
if trocar == 1:
porta = int(input("Digite a porta: "))
if porta ==premio:
print("Ganhou")
break
else:
print("Não ganhou! Que pena!")
In my tests the program is working but I would like a more pythonic solution to learn the style!