Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJarlei 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,712 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,712 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,712 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,712 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,712 PointsSteve Hunter
57,712 PointsCan you post your code, please?
Steve.