Reputation:
I have the following code:
from random import randint
Roll=[]
for i in range(3):
zari=randint(1,6)
Roll.append(zari)
for b in Roll:
the above code is deficient.
What i want my code to do is if inside the Roll list is the combination of numbers 4,5,6 to print('Player won')
but im kinda lost
Any suggestions?
The player wins if the combinations of the numbers is 4,5,6 and he loses if the combination is 1,2,3.This is the code that i managed to make but i cant figure out the rest of it
Also i forgot to mention that player wins if the combination is 2 same numbers followed by the number 6 for example 2,2,6. Any ideas on this ?
Thank you for every answer
Upvotes: 4
Views: 223
Reputation: 86
Its a game called Cee-lo.
Check out my code:
from random import randint
while(True):
Roll=[]
for i in range(3):
zari=randint(1,6)
Roll.append(zari)
if set(Roll)=={4,5,6}:
print('Player won'); break
elif set(Roll)=={1,2,3}:
print('Player lose'); break
# If Roll has two same values, set() will remove duplicate value
elif len(set(Roll))==2 and 6 in Roll:
print('Player won',Roll); break
else:
print('Rolling the dice again')
Upvotes: 1
Reputation: 10624
Try by comparing your result (Roll) with the set {4,5,6}:
if set(Roll)=={4,5,6}:
print('Player won')
Full code:
from random import randint
Roll=[]
for i in range(3):
zari=randint(1,6)
Roll.append(zari)
if set(Roll)=={4,5,6}:
print('Player won')
Upvotes: 3
Reputation: 987
If I understood correctly, you want to check at any given time if Roll
contains 4, 5 and 6. In that case, just do this: 4 in Roll and 5 in Roll and 6 in Roll
, which will return a Boolean
Upvotes: 1