LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-09-2004, 10:19 AM   #1
sethgeekx86
Member
 
Registered: Jan 2004
Distribution: Slackware 9.1 SUSE 9.0
Posts: 131

Rep: Reputation: 15
Python Random number


I am trying to write a python script that asks a user for a number and then picks a random whole number betwen 1 and the imputed number , including 1. Heres what i have i need help on the random part
Code:
#!/usr/bin/python
# Filename : number.py
from random import Random
guess = int(raw_input('Enter a Number  : '))
print guess
 
Old 06-09-2004, 12:40 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Boy, this sounds like homework.
 
Old 06-09-2004, 12:43 PM   #3
sethgeekx86
Member
 
Registered: Jan 2004
Distribution: Slackware 9.1 SUSE 9.0
Posts: 131

Original Poster
Rep: Reputation: 15
If someone could just point me to a tutorial on random it would be help full
 
Old 06-09-2004, 07:46 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
From the obvious place:

http://docs.python.org/lib/module-random.html
 
Old 06-10-2004, 08:55 AM   #5
sethgeekx86
Member
 
Registered: Jan 2004
Distribution: Slackware 9.1 SUSE 9.0
Posts: 131

Original Poster
Rep: Reputation: 15
Code:
#!/usr/bin/python
# Filename : r.py
import random 
p = int(raw_input('Enter a number: '))
number = random.randint(1,p)
print "and the number is" , number
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
random number generation sailu_mvn Programming 4 03-10-2005 02:10 PM
Random number generators blufire Programming 5 11-09-2004 06:02 PM
Random Number Game tearinox Programming 4 08-20-2004 10:12 PM
Python problems trying to generate a random number davholla Programming 0 10-27-2003 04:07 AM
I need random number in C ... purpleburple Programming 4 10-28-2002 04:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration