-3

creating a tuple that holds the values 1 through 6. Roll the dice by calling a function and display the random roll. For this example, let’s assume that the random roll is (2, 1, 5, 1, 5). The following message will be displayed: Rolling the dice... (2, 1, 5, 1, 5)

then from the random add implementing a counter function that adds up the values of the dice roll. For example.

(0, 2, 0, 0, 10, 0) since there were no zeros rolled the first number will be zero, second since there was 2 1's drawn they will add up to 2 and so on so fourth.

I have tried using this as my code.

from random import shuffle 

roll_number = [1,2,3,4,5,6]
shuffle(roll_number)
print(f'Rolling the dice...{roll_number}')

from collections import Counter

lst = (roll_number)
c = Counter()
for n in lst:
    c[n] += 1
    
for i in set(lst):
    print(i * c[i])

but it prints out the same value every function call.

1 Answers1

-1

You may want to check out https://stackoverflow.com/help/how-to-ask, as this question isn't very clear and doesn't isolate the issue, but I believe I understand what you are asking.

import random
#this should have a more intuitive name like potential_results
roll_number = [1,2,3,4,5,6]
#It looks like you need 5 rolls
NUM_ROLLS = 5

#make a dictionary to track the values, google dictionary or hashmap for more info
roll_count = {v: 0 for v in range(1, 7)}
#curr rolls since we also need to print the specific rolls
curr_rolls = []
for i in range(NUM_ROLLS):
     roll = random.choice(roll_number)
     roll_count[roll] += 1
     curr_rolls.append(roll)

print(f'Rolling dice... {tuple(curr_rolls)}')

#now create tuple with values total values
total_values = (roll_count[1] * 1, roll_count[2] * 2, roll_count[3] * 3, roll_count[4] * 4, roll_count[5] * 5, roll_count[6] * 6)

print(total_values)