473,670 Members | 2,677 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 1226
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
2373
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 'unverified' subscribers in a different table, aside from organization? I did just that, where, when they subscribe, they are put in a temp table, and them moved to the real table once verified (and the temp entry deleted). At the time, I did this...
20
4162
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, just something that isn't plain-text and it HAS to be as unique as the original number. It also does not need to be a symmetric algorithm - we are using this as a way to create a unique "userid" on a system to which we single-signon. So it's used...
17
20475
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 found a few that add the check digit then do the final calc, but I need an input validation that will verify the UPC as being correct with the correct check digit after the user simply enteres the number in one text box. There has to be something...
3
9321
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 script for 8-digit (UPC-E) type script? I don't want to convert it to a 12-digit UPC-A before validating it as a 12-digit number. I would prefer to just be able to calc the number, as an 8-digit number, check digit and all, just like I am currently...
11
17787
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 greater number than second 20 digit number ,then it should return.
7
4838
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
6556
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 second iteration it should return the number 5, and so on. But for some reason on the first iteration returns the expected results. Each subsequent iteration returns the number plus 1. In order words, when I run the program I am getting: 7, 6, 4, and...
2
27332
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 so forth. For example, if the number entered by the user is 4321 then, int array = 1 int array = 2 int array = 3 int array = 4 int array = '\0' (End of array - when number == 0) This is the piece of code i...
7
2204
by: southernsunsations | last post by:
/******************************************************************\ * * * * Date: 09.06.2007 * \******************************************************************/ // Example: num digit // A // B // C // D
14
8651
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, but we started facing issues once we go above 15 digits. Thanks, Venkat
0
8903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8815
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7421
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5686
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4213
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.