Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 21st, 2004, 06:46 PM
Ice Man Ice Man is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 Ice Man User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
newbie needs help whith his first project

i have a small problem. i have no clue how to create a random number. i tried to look it up but that all goes way over my head. i had a problem getting the program to play more than once but my friend pointed me in the right direction with the test thing, then told me to figure out the number thing i needed to go ask other programers. or go make my own solution, so after much cussin i came looking for help. please help me.
test = 1
while test == 1:
print "Do ya wanna play a game?"
guess = input("Guess a number between 1 and ten.")
if guess == 5:
print "Your Right!"
else:
print "Sorry, thats not it."
print "Do you want to play again?"
print "y or n"
y = 1
n = 0
answer = input("> ")
if answer == 0:
test = 0;
print "Okay, maybe some other time then."

Reply With Quote
  #2  
Old June 21st, 2004, 06:56 PM
NetBSD NetBSD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Canada
Posts: 234 NetBSD Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 9 h 25 m 35 sec
Reputation Power: 0
Send a message via MSN to NetBSD
From the random module docs:

Quote:
randint(a, b)
Return a random integer N such that a <= N <= b.


So use :

Code:
import random
random.randint(min, max) #replace min and max with your values


Also, in your code you don't need to use the test variable, you can just use:

Code:
while True:


and then use:

Code:
if answer == 0:
    break


Also, from what is looks like, you don't need the y and n variables at all.

and don't forget to use [ code ] [ /code ] tags next time (http://forums.devshed.com/misc.php?do=bbcode#code).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > newbie needs help whith his first project


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT