Creating dice game : NEED HELP ON CHECKING ELEMENTS IN A LIST

bob gailer bgailer at gmail.com
Sat Oct 6 19:54:18 EDT 2018


# your program is quite complicated. classes are overkill. A simpler 
solution is:
import random
for i in range(5):
     roll = random.randint(1,6)
     if roll not in (1,5):
         print('you can roll again')
         break
else:
     print("you have all 1's and 5's in your result'")

# comments on  using classes:
class Dice:
     ...
# no need for die1...die5 - use list comprehension:
alldice = [Dice(6) for i in range(5)]

# object is a bult-in type. it is inadvisable to assign to names of 
built-ins
# as this makes the built-in unavailable. Look up builtins (module) in 
help for
# a complete list.

# use list comprehension roll and report:
print([d.roll_dice() for d in alldice])




More information about the Python-list mailing list