469,616 Members | 1,806 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Digit Gen, easy for the pros ;)

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
6 1151
ilikepython
844 Expert 512MB
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
shing
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
844 Expert 512MB
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
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
6,596 Expert 4TB
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
844 Expert 512MB
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.

Similar topics

reply views Thread by Sniffle | last post: by
17 posts views Thread by Kermit Piper | last post: by
3 posts views Thread by Kermit Piper | last post: by
11 posts views Thread by balakrishnan.dinesh | last post: by
8 posts views Thread by Candace | last post: by
14 posts views Thread by thehobbit | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.