So I have the following code:
from random import *
def main():
die1 = randint(1,6)
die2 = randint(1,6)
dietotal = die1 + die2
print dietotal
main()
Now I am expecting a random integer that is the summation of die1 and die2. What I get, however, is a syntax error which highlights dietotal in the print statement. All randint does is return a random integer so I shouldn’t have a problem here. Why am I getting this syntax error?
Probably you’re using Python 3, and that’s a Python 2 style print statement. For example:
but
In Python 3,
printis a function, not a statement, and so you need parentheses: