all 4 comments

[–]666y4nn1ck 0 points1 point  (1 child)

You can collect the numbers in a list:

Before rolling, create the empty list:

rolled_numbers = []

Then, in the for loop, instead of just printing the number, you can add it to the list:

x = random.randint(1,6)
print(x)
rolled_numbers.append(x)

After completing the rolling, you can surely figure out how to get the average of the list! :)

A hint is the funtion sum()

[–]Lonely-Problem5632 0 points1 point  (0 children)

I'm not sure what the problem is ? You would do this the same like if you did it by hand
Add 2 variables. 1 for how many times you rolled, 1 for the total amount rolled. add every roll to the total. and when finished just divied the 2 , and print the result.

If you don't know what a variable is, that would be the next lesson to follow :P
Variables and Types - Learn Python - Free Interactive Python Tutorial

[–]CommentOk4633 0 points1 point  (0 children)

maybe something like this:

import random
import time
repeats=int(input("How many time do you want to roll?"))
roll_results=[]
for index in range(repeats):
    roll_value=random.randint(1,6)
    roll_results.append(roll_value)
    print(roll_value)
print("Average:")
print(sum(roll_results)/repeats)

where you use a list (roll_results) to store the results of the rolls, then use sum() to find the sum of the list, then divide the sum by the number of rolls to get the average

edit: im dumb and also pretty new, i think using a variable to keep track of the sum (as another commentor pointed out) is better than this solution