|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Random Number Generating (Whole numbers)
Hi all,
I am using the following code and am getting errors thrown at me, but I can't understand why? Code: from random import Random, random num = random.randint(10,20) print num End of code. The error is saying that I can't import name random? So obviously the error lies on line 1. Can anyone see what might be causing this error? Cheers
__________________
Tryst |
|
#2
|
|||
|
|||
|
It seems that it was my file name that was causing the problem (random.py).
I am still getting an error, though. Through the same code as in the previous post, I am getting the folowing error message... 'function' object has no attribute 'randint' Anyone see where I am going wrong? Cheers |
|
#3
|
||||
|
||||
|
Try this instead:
Code:
import random num = random.randint(10, 20) print num or this: Code:
from random import randint num = randint(10, 20) print num
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month Last edited by Scorpions4ever : February 13th, 2004 at 09:35 AM. |
|
#4
|
|||
|
|||
|
Cheers, the second section of code works fine.
Tryst |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Random Number Generating (Whole numbers) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|