Python Forum
Please help me add all the results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please help me add all the results
#1
Thumbs Up 
Hey all, Im trying to code dice rolls that all get added together

Two pieces of code here, first bit generates all the numbers and prints then out, the second set of code is me try to get it added all together

please help

#working code
import random


def D4(x):
    
    for d4 in range(x):
        d4 = (random.randint)(1,4)  
        
        print(d4)
#eg
D4(10)
################################################


#my best attempt
import random

def D4(x):

    rolls = 0
    for d4 in range(x):
        d4 = (random.randint)(1,4)  
        rolls = rolls + d4
        
        return rolls
                            
def dicetotals(x):
    print(D4(x))

dicetotals(2)
Larz60+ write Dec-10-2020, 11:33 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Please help me add all the results - by mr_kungfu - Dec-10-2020, 08:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,248 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to append one function1 results to function2 results SriRajesh 5 3,180 Jan-02-2020, 12:11 PM
Last Post: Killertjuh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020