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 trial
Keeri Tramm
1,806 PointsBeginner Python syntax error
I'm trying to do a random number generator in Python, but I keep getting a syntax error in line 4. Any ideas? Thank you in advance!!!
import random
for x in range(10): print random.randit(1,101)
Jen Farrant
6,905 Pointsit is easier for people to help you if you share the code rather than as text
print("This is easier to read")
look at the markdown cheatsheet linked below for how to use it
1 Answer
ursaminor
11,271 PointsYour print syntax is Python 2 and I'm assuming you're running this with Python 3. In Python 3 print requires (). Also randint is spelled wrong. So it should be:
import random
for x in range(10):
print(random.randint(1, 101))
Amaan Sheikh
Python Web Development Techdegree Student 31 PointsAmaan Sheikh
Python Web Development Techdegree Student 31 Pointswhy you 're running loop to generate random number ?
import random
x = random.randint(0, 10) print(x)