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

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay