1
import random
min = 1
max = 6

roll_again = "yes"

while roll_again == "yes" or roll_again == "y":
    print ("Rolling the dices...")
    print ("The values are....")
    print random.randint(min, max)
    print random.randint(min, max)

    roll_again = raw_input("Roll the dices again?")

and this is the error

  File "main.py", line 10
    print random.randint(min, max)
               ^
SyntaxError: invalid syntax

Where am I going wrong and how do I fix ?

001
  • 13,291
  • 5
  • 35
  • 66
Harry
  • 11
  • 1

2 Answers2

2

You need parentheses for your print() calls. Try this:

print(random.randint(min, max))

Also, since you're using Python 3 you should use input() instead of raw_input().

Jacob Lee
  • 4,405
  • 2
  • 16
  • 37
QWERTYL
  • 1,355
  • 1
  • 7
  • 11
1

Between Python 2.7 and Python 3.0, print changed from a statement to a function. The line producing your error was perfectly valid in Python 2.7, but functions require their arguments to be enclosed in parentheses. In this case, Python encountered a function name that wasn't followed by an opening parenthesis so it didn't know how to interpret what followed. Even though the error pointed to random as the problem, the error actually occurred prior to that. As @QWERTYL pointed out the solution is very simple, turn the print into a proper function call by putting the arguments inside parentheses.

print(random.randint(min, max))

P.S. don't use variable names like min and max, those are already used by Python itself and can lead to some hard to find bugs. Maybe smallest and largest would be better.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622