Question
Part 4: Counting the Dice Goal: Now that we can roll some dice, we need to be able to count each die and add
""" Part 4: Counting the Dice
Goal: Now that we can roll some dice, we need to be able to count each die and add up their total value.
Reuse some of the functions you wrote in Part 3, and we'll create two more functions that will find the value of each rolled die and sum them all up. """ #Task1 def dice_list(no): #function to print dice face if no == 1: print("[-----]") print("[ ]") print("[ 0 ]") print("[ ]") print("[-----]") if no == 2: print("[-----]") print("[ 0 ]") print("[ ]") print("[ 0 ]") print("[-----]") if no == 3: print("[-----]") print("[ ]") print("[0 0 0]") print("[ ]") print("[-----]") if no == 4: print("[-----]") print("[0 0]") print("[ ]") print("[0 0]") print("[-----]") if no == 5: print("[-----]") print("[0 0]") print("[ 0 ]") print("[0 0]") print("[-----]") if no == 6: print("[-----]") print("[0 0 0]") print("[ ]") print("[0 0 0]") print("[-----]") #Task2 def dice_roll(): #function to roll dice num = random.randint(1,6) return dice_list(num) #Task3 def roll_lots_of_dice(how_many = 1): #function to roll the dice how_many times roll_list = [] roll_list.append(dice_roll()) return roll_list import random
def dice_list(): """Create and return a list of die faces"""
### YOUR CODE HERE ###
def dice_roll(): """ Return a randomly selected die face from the list of dice faces that is returned from calling dice_list() """ ### YOUR CODE HERE ###
def roll_lots_of_dice(how_many=1): """Return a list of "rolled dice"."""
### YOUR CODE HERE ###
""" Task 1: Create a function that takes in a die face, and returns its INTEGER value. """ def get_dice_value(die_face): """ Returns the INTEGER value of a die face.
Example: -If ".." is passed as argument, then 2 should be returned -If "....." is passed as argument, then 5 should be returned """
### YOUR CODE HERE ###
""" Task 2: Create a function that takes in a LIST of the rolled die faces and returns the sum.
Example: -If ['.', '...'] is passed in, should return 4 -If ['...', '..', '.'] is passed in, should return 6 """ def add_up_rolled_dice_faces(list_of_rolled_faces): """ Returns the sum of a list of rolled die faces."""
### YOUR CODE HERE ###
if __name__ == "__main__":
""" Task 3: Keep asking the user for input (how many dice to roll) until they input 0.
Output the LIST of all the "rolled" die faces each time, and the sum of those dice """
### YOUR CODE HERE ###
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started