I just started my first programming class a few weeks ago and I'm embarrassed to say I'm very stuck. We had to create a program that (in my Professor's words):
Simulate the roll of two dice. Use a randomly generated integer to represent the roll of each die in a function named point. Return the combined value of a roll. Use a loop in main to roll the dice five times and report each result.
So, I did my best and keep getting the same issue where it is telling me my variable total is not defined, even though I'm calling the function which contains the variable.
I submitted the below code to my professor, who in turn responded:
The dice program is close. Return the total of a roll. Call point in main and capture the returned value for printing.
So he is saying to call the function point in my main function (which, at least I think, I am) but it still won't read my vital variable to finishing this.
import random
min=1
max=6
def main():
for roll in range(5):
point()
print(total)
def point():
roll=random.randint(min, max)
roll2=random.randint(min, max)
total=roll+roll2
return total
main()