i try to make a dice in python where it allows up to 3 dice if it is 3 times the same the player will go to jail. but i'm stuck with the actions at counter 2 where it will reply go back to jail instead of printing it one million times what is happening with my console right now every time. and if i insert the break on the correct place it wont print out 1 + 1 = go directly to jail instead it completely ignores that statement. can someone please help me.
import random
def monopolyworp():
counter = 0
while True:
d1 = random.randint(1,7)
d2 = random.randint(1,7)
# d1 = 3
# d2 = 3
# lst = d1,d2
print(f"{d1}+{d2}={d1+d2}")
if d1 == d2:
counter += 1
continue
if counter == 2:
a = d1
b = d2
x = d1,d2
if a == b:
print(f"{a} + {b} = direct naar de gevangenis")
break
elif a != b:
print(f"{a}+ {b} = {sum(x)}")
break
monopolyworp()
output has to be:
>>> monopolyworp()
1 + 2 = 3
[(1, 2)]
>>> monopolyworp()
4 + 4 = 8
4 + 5 = 9
[(4, 4), (4, 5)]
>>> monopolyworp()
3 + 3 = 6
4 + 4 = 8
1 + 1 = direct naar gevangenis
[(3, 3), (4, 4), (1, 1)]
>>> monopolyworp()
3 + 3 = 6
4 + 4 = 8
1 + 2 = 3
[(3, 3), (4, 4), (1, 2)]
Aucun commentaire:
Enregistrer un commentaire