473,372 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 1214
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

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

Similar topics

0
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
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
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
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
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
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
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
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
by: southernsunsations | last post by:
/******************************************************************\ * * * * Date: 09.06.2007 ...
14
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.