Question: Python 3.6 - I am creating a game where the player rolls dice and is rewarded points. To take a turn, a player rolls all
Python 3.6 -
I am creating a game where the player rolls dice and is rewarded points.
To take a turn, a player rolls all five dice, and scores them as follows. If player rolls:
five 2's = 200 points five 4's = 400 points five 5's = 500 points five 6's = automatically win the game five 1's = automatically lose the game
three 2's = 20 points three 3's = 30 points three 4's = 40 points three 5's = 50 points three 6's = 60 points three 1's = 100 points
This is the part I have already completed (seen in the code below).
________________________________________________________________________________________________________________
Here's the part I need help with:
If player don't score any of the above, for each die that comes up 5 he get five points, and for each die
that comes up 1 he get ten points. If he get a flash other than 5s or 1s you also count the individual dice that come up 5 or 1 for five or ten points, respectively.
Please complete the part I need help with and provide indented source code as well as comments to help me understand. Thanks.
Here's the code:
import random def RollDie(sides): r = random.randrange(1, sides + 1) return r def is_count(a, num, count): return a.count(num) == count def five_twos(a): return is_count(a, 2, 5) def five_sixes(a): if is_count(a, 6, 5): print("You've won the game.Congrats!!!!") return True return False def five_ones(a): if is_count(a, 1, 5): print("You've lost the game. Sorry!") return True return False def five_fours(a): return is_count(a, 4, 5) def five_fives(a): return is_count(a, 5, 5) def three_twos(a): return is_count(a, 2, 3) def three_fives(a): return is_count(a, 5, 3) def three_threes(a): return is_count(a, 3, 3) def three_sixes(a): return is_count(a, 6, 3) def three_fours(a): return is_count(a, 4, 3) def three_ones(a): return is_count(a, 1, 2) # dice should be rolled and then checked all conditions rather than rolling in each function # rolling 5 dice and storing the result in array a a = [RollDie(6) for i in range(0,5)] print(a) if not five_sixes(a): if not five_ones(a): points = 0 if five_twos(a): points = 200 elif five_fours(a): points = 400 elif five_fives(a): points = 500 elif three_twos(a): points = 20 elif three_fives(a): points = 50 elif three_threes(a): points = 30 elif three_sixes(a): points = 60 elif three_fours(a): points = 40 elif three_ones(a): points = 100 print("you have gained " + str(points) + " points") Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
