DEV Community

Max Lindh
Max Lindh

Posted on

Hi I am new to programming I have encountered a problem is that when I write import random I encounter syntaxerror in Python.

Top comments (3)

Collapse
 
ahmedesmail07 profile image
Ahmed Esmail

Welcome to programming world, make sure that you have these correctly:
1- Spelling of the import, it should be import random.
2- Make sure the indentation correctly done by using the tab button.
3- Make sure that your file.py should not be random.py this will raise some issues related to the random module.

Collapse
 
linkbenjamin profile image
Ben Link

Hi Max! The suggestions provided in the other comments cover the most likely scenarios - be sure to let us know what happens! We'll be happy to jump in and help get you rolling again, if those ideas don't solve the problem - we'll just need a little more detail about what you're seeing if that's the case!

Collapse
 
devesh_joshi_58ce1b2898d1 profile image
Devesh Joshi

I am making a random guess here for the error as getting syntax error for an import is unusual.
Make sure you are importing random at the top of your file i.e. first line.
Second, check if you have name your .py file as random.py