mraraju
mraraju

Reputation: 11

Random number generator does not work

I am trying to create a random number in Python. For some reason the code shown below does not work.

import random    
print random.random()

I receive the following error:

invalid syntax

If anyone has any pointers, I will greatly appreciate it.

P.S. The above code works on some computers (2 out of 30 in a room).

Upvotes: 1

Views: 139

Answers (1)

austin-schick
austin-schick

Reputation: 1245

If python 3 is being used, then print is a function and must be called like

print (random.random())

This would also explain why the code works on two computers. They might be running a different version of python.

Upvotes: 3

Related Questions