I need to run a random 6 sided dice twice and return the sum of them. I am not sure if this is right but I don’t think it is, I am still learning python so I am pretty new when it comes to this kind of stuff.
import random
def roll_die():
roll1 = random.randint(1,6)
roll2 = random.randint(1,6)
total = roll1 + roll2
return total
It works.
It is also best practice to initialize the random generator by calling:
at the beginning of your script, even if it is not necessary, and it is not a mistake to omit it.
If you want to test it, add the following:
at the end of the script, to print the result, since the return keyword does not print anything on the screen, it is only used to let the result of the function out.