473,511 Members | 10,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Digit Gen, easy for the pros ;)

58 New Member
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 1218
ilikepython
844 Recognized Expert Contributor
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 New Member
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 Recognized Expert Contributor
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
William Manley
56 New Member
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 Recognized Expert Expert
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 Recognized Expert Contributor
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

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

Similar topics

0
2348
by: Sniffle | last post by:
Thanks... Say you have a double opt in mailing list, of which the subcriber list is store in the db. Im still somewhat of a newb, so bear with me... are there any pros/cons as to keeping the...
20
4130
by: Drebin | last post by:
It's a long story really, but the bottom line is we need to encrypt or obfuscate a clear-text 9-digit SSN/taxpayer ID into something less than 21 characters. It doesn't need to be super-secure,...
17
20440
by: Kermit Piper | last post by:
Hello, I have been searching, Googling, searching. Cannot find a javascript to calc 10, 11 or 12 digit UPC codes. I just need an algorithm that calcs to verify the correct check digit. I have...
3
9311
by: Kermit Piper | last post by:
Hello everyone, OK, let me try and explain again please. Here is what I'm trying to do. I have a 12-digit (UPC-A) javascript validation script which works great. All I need now is a similar...
11
17751
by: balakrishnan.dinesh | last post by:
hi frnds, Im having two 20digit numbers, But while comparing those it is giiving wrong ouput in javascript. for example here is my code, my secanrio is , ~ If first 20 digit number is...
7
4823
by: ffrugone | last post by:
I need to create a method for a web page I'm building that encrypts a number from 1 to 1000 into a 4 digit hex code. I know nothing about cryptography. Can anyone steer me in the right direction?
8
6545
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
2
27285
by: hikmaz | last post by:
I am trying to get the rightmost digits (%10) of a number (taken from the user) and store it into successive array locations and get rid of the rightmost digit (\10) to store the next and so on and...
7
2194
by: southernsunsations | last post by:
/******************************************************************\ * * * * Date: 09.06.2007 ...
14
8633
by: thehobbit | last post by:
Hi, Could anyone give ideas on how to add 4 20 digit numbers in ANSI C and pass the result back to a calling program in COBOL? We were able to add up to 15 digit numbers without any problems,...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
451
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.