How do you assign a random int to a variable more then once
say i use this code

import random
x = 1
while x == 1:
    random = random.randint(1,100)
    print random
    raw_input ("Push <enter> to print another random number")

It will print out the first random number but the second time it prints this error.

Traceback (most recent call last):
  File "C:/Documents and Settings/tony taylor/Desktop/Idearatizer/random.py", line 4, in <module>
    random = random.randint(1,100)
AttributeError: 'int' object has no attribute 'randint'

How do you get past this.
Thanks

Recommended Answers

All 2 Replies

Problem is you're naming your output variable random. Use another name!

After you do your import random you've defined an object named random that basically contains a bunch of procedures such as randint(). You're overwriting all that with some random integer and that's why you get an error the second time around.

:icon_eek: That easy. Fixed it. Thanks man

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.