AttributeError: module 'random' has no attribute 'randint'

Answered

I am getting an error, while writing a simple random number generating code.

How can this be resolved. I just recently took up learning python and tried to code in pycharm.

0
2 comments

Hello!

If you run this script with the same python interpreter in the Terminal, you will get the same result so the problem is not Pycharm-related.

This error happens because of imports order in python: first, python looks at your local modules and then go to the system ones. In your case, python found your project module `random` instead of a standard python module with the same name - that's why you got this error message.
You need to rename your project file "random.py" to something else.

3
Avatar
Permanently deleted user

thank you! I had the same problem:-)

0

Please sign in to leave a comment.