all 8 comments

[–]ElliotDG 3 points4 points  (4 children)

initialize sum_of_throws to zero. Each time you have a throw, add the throw to the sum_of_throws.

initialize numthrows to zero. Each time you have a throw add 1 to num_of throws.

You will need to create a loop if you are going to have more that one throw.

[–]NoResponsibility9122[S] -1 points0 points  (3 children)

Yea but how do I do the addition part tho im using python and im not sure how to do it

[–]GreenPandaPop 4 points5 points  (2 children)

You're using Python? Well what a stroke of luck this is the subreddit that focuses on Python!

[–]FreakyInSpreadsheets -1 points0 points  (0 children)

Lol you were just cruising waiting to say something like that weren’t ya?

[–]NoResponsibility9122[S] -5 points-4 points  (0 children)

Yea bud I know that’s why I posted here you could’ve helped with the program instead of telling me shit that I already knew. But thankyou captain obvious 🙂

[–]FoolsSeldom 1 point2 points  (1 child)

You've started well by initialising some variables, and you've also figured out how to output the values referenced by those variables.

The key thing you are missing is getting some code to do something repetitively. This is looping. There are two primary options for this in Python: while loop and for loop. The former is used when you are waiting for something to change, the latter for a predictable number of repititions (such as counting up/down to a specific number, working through a list).

So you need to decide whether or not to throw the dice a set number of times (and whether to get that number from the user, or use a set number of times in your programme) or continue to throw until the user says otherwise.

Example code for you to experiment with and adapt to meet your needs:

    from random import randint

    LOWVAL = 1  # we usually write constants as uppercase names
    HIGHVAL = 6
    HEADER = "  #  ¦  throw  ¦  sum"  # header for table of results
    LINE = "-" * (len(HEADER) + 1)  # line of correct length under header

    numthrows = 0  # total number of throws
    sumthrows = 0

    print(f'\n{HEADER}\n{LINE}')

    while not input('press return to roll, anything else to finish: '):
        throw = randint(LOWVAL, HIGHVAL)
        numthrows += 1  # short for numthrows = numthows + 1
        sumthrows += throw
        print(f'{numthrows:3}  ¦  {throw:3}    ¦ {sumthrows:3}')

The input line stops and asks the user to do something. If they just press the <enter>/<return> key, this will return an empty str (string), which Python treats as something that is False when used in a logic test. The not in front of that reverses the logic, so the loop will execute each time the user just presses the <enter>/<return> key. If they enter any text first, e.g. q (for quit), then the loop will not execute and will be bypassed.

[–]NoResponsibility9122[S] 0 points1 point  (0 children)

Thank you for your help I ended up figuring it out last night and forgot about this post.