
Jarlei Sassi
5,180 PointsCannot import random library
Traceback (most recent call last):
File "guess_game.py", line 1, in <module>
import random
File "/usr/local/pyenv/versions/3.5.0/lib/python3.5/random.py", line 41, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ImportError: cannot import name 'log'
5 Answers

Jarlei Sassi
5,180 Pointsimport random
cont = 1
num = randint(1,10)
print("##### Guess game ####")
while cont < 6:
try:
guess = int(input("Enter a number between 1 to 10"))
except ValueError:
print("Entre com um numero")
cont = cont + 1

Steve Hunter
57,667 PointsHi there,
Thanks for the code.
I think you need to call randint
on random
like num = random.randint(1, 10)
Give that a go.
Steve.

Jarlei Sassi
5,180 PointsNo, same problem.
The error is in the first line :/

Steve Hunter
57,667 PointsThe error reporter is picking up on something in the random
class being used wrongly - the error is within the usage of part of the random
class. The error can sometimes appear really unhelpful! Clearly, there's nothing wrong with the random
class itself as we haven't touched it!
I ran this code with no error:
import random
cont = 1
num = random.randint(1,10)
print("##### Guess game ####")
while cont < 6:
try:
guess = int(input("Enter a number between 1 to 10"))
except ValueError:
print("Entre com um numero")
cont = cont + 1
I'll try to post a screenshot of the code working - this may take a few attempts, though as I always get it wrong! Now visible - only two attempts at it!!

Steve Hunter
57,667 PointsMight be worth saving your workspace and restarting it to see if that helps. Your code is working OK here, with that small amendment.

Jarlei Sassi
5,180 PointsI've created a new folder and a new file. Now it works

Steve Hunter
57,667 PointsVery strange - glad you got it fixed!

Jarlei Sassi
5,180 PointsIt's strange because when I ran this code It was running a function from another file. o.O
Steve Hunter
57,667 PointsSteve Hunter
57,667 PointsCan you post your code, please?
Steve.