By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

Digit Gen, easy for the pros ;)

P: 58
Expand|Select|Wrap|Line Numbers
  1. import random                     #not sure about this
  2.  
  3. while True:
  4.     guess = raw_input("Start or Exit?")
  5.     if guess.lower() == 'exit':
  6.               break
  7.  
  8.     if guess.lower() == 'start':
  9.  
  10.         a = raw_input("Digits?")
  11.  
  12.         random() == (1-9)
  13.  
  14.         print random()
  15.  
  16.  
  17.     else:
  18.         print 'Invalid entry'
  19.  
Just a simple question guys; What's wrong with my coding?

This is the error i get:

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Program Files\Python25\diggen.py", line 35, in <module>
  3.     random() == (1-9)
  4. TypeError: 'module' object is not callable
  5.  
Aug 11 '07 #1
Share this Question
Share on Google+
6 Replies


ilikepython
Expert 100+
P: 844
Expand|Select|Wrap|Line Numbers
  1. import random                     #not sure about this
  2.  
  3. while True:
  4.     guess = raw_input("Start or Exit?")
  5.     if guess.lower() == 'exit':
  6.               break
  7.  
  8.     if guess.lower() == 'start':
  9.  
  10.         a = raw_input("Digits?")
  11.  
  12.         random() == (1-9)
  13.  
  14.         print random()
  15.  
  16.  
  17.     else:
  18.         print 'Invalid entry'
  19.  
Just a simple question guys; What's wrong with my coding?

This is the error i get:

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Program Files\Python25\diggen.py", line 35, in <module>
  3.     random() == (1-9)
  4. TypeError: 'module' object is not callable
  5.  
I don't know what you are tyring to do. random is a module and 1-9 means one minus nine. Myabe something like this:
Expand|Select|Wrap|Line Numbers
  1. while True:
  2.     guess = raw_input("Start or Exit?")
  3.     if guess.lower() == 'exit':
  4.         break
  5.  
  6.     if guess.lower() == 'start':
  7.         a = raw_input("Digits?")
  8.         nums = [int(x) for x in a.split()]
  9.         if random.randint(1, 10) in nums:
  10.             print "good"
  11.        else:
  12.            print 'Invalid entry'
  13.  
Aug 11 '07 #2

P: 58
Doesn't seem to work....I'm trying to make a digit generator...you know? Something that displays 10 digits if you ask it to...
Aug 12 '07 #3

ilikepython
Expert 100+
P: 844
Doesn't seem to work....I'm trying to make a digit generator...you know? Something that displays 10 digits if you ask it to...
What do you mean it doens't work? Besides an indentation error, I'm pretty sure it works. Something like this?
Expand|Select|Wrap|Line Numbers
  1. import random
  2.  
  3. if raw_input("Do you want to display 10 digits? ") in 'Yy':
  4.     for dummy in range(10):
  5.         print randint(1, 10)
  6.  
Aug 12 '07 #4

P: 56
Expand|Select|Wrap|Line Numbers
  1. import random
  2.  
  3. if raw_input("Do you want to display 10 digits? ") in 'Yy':
  4.     for dummy in range(10):
  5.         print randint(1, 10)
  6.  
I do believe you either need to change "randint" to "random.randint" or change "import random" to "from random import randint"
Aug 12 '07 #5

bartonc
Expert 5K+
P: 6,596
What do you mean it doens't work? Besides an indentation error, I'm pretty sure it works. Something like this?
Expand|Select|Wrap|Line Numbers
  1. import random
  2.  
  3. if raw_input("Do you want to display 10 digits? ") in 'Yy':
  4.     for dummy in range(10):
  5.         print randint(1, 10)
  6.  
Our friend, William Manley, is correct. The import is one way to fix this:
Expand|Select|Wrap|Line Numbers
  1. from random import randint
Or on this line:
Expand|Select|Wrap|Line Numbers
  1. #
  2.         print random.randint(1, 10)
BTW, I notice that you are still typing your CODE tags in (I did it that way for a long time, too). Then I found that setting the "Enhanced Mode" radio button and using the # button is much faster and less error prone.

Hope that helps.
Aug 12 '07 #6

ilikepython
Expert 100+
P: 844
Our friend, William Manley, is correct. The import is one way to fix this:
Expand|Select|Wrap|Line Numbers
  1. from random import randint
Or on this line:
Expand|Select|Wrap|Line Numbers
  1. #
  2.         print random.randint(1, 10)
Yep, he's right, I missed that sorry.
BTW, I notice that you are still typing your CODE tags in (I did it that way for a long time, too). Then I found that setting the "Enhanced Mode" radio button and using the # button is much faster and less error prone.

Hope that helps.
Thanks, I'll try that.
Aug 12 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.