473,327 Members | 2,055 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,327 software developers and data experts.

High Low game

I am trying to write a program in Python for a High Low guessing game. It has to tell the person if their guess is higher or lower, also keep track of their guesses, it also needs to ask them if they would like to play again and loop back to the beginning when done. I have most of it done but I am having problems with making it play again. This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. # Guess My Number
  2. # The computer picks a random number
  3.  
  4. def begin ():
  5.  import random
  6. print "\tWelcome to 'Guess my Number'!:"
  7. print "\nI'm thinking of a number between 1 and 100."
  8. print "Try to guess it in as few attempts as possible.\n"
  9.  
  10. def guess_num(num, max_guesses):
  11.     # guessing loop
  12.     tries = 0
  13.     while True:
  14.         guess = int(raw_input("Take a guess: "))
  15.         tries += 1
  16.         if guess > num:
  17.             print "Lower..."
  18.         elif guess < num:
  19.             print "Higher..."
  20.         else:
  21.             print "You guessed it! The number was", num
  22.             print "And it only took you %d tr%s!\n" % (tries, ['ies', 'y'] [tries==1 or 0])
  23.             return
  24.  
  25.         if tries == max_guesses:
  26.             print "You have had %d guesses. Game over." % max_guesses
  27.             return
  28.         play = raw_input("Do you want to play again? Y/N")
  29.         if play == "Y":
  30.              begin ()
  31.         if play == "N":
  32.              print "Well you are no fun. Bye."
  33.  
  34.  
  35.  
  36.  
  37. the_number = random.randrange(1,100)
  38. max_guesses = 5
  39. guess_num(the_number, max_guesses)


Any help would be greatly appreciated.
Feb 13 '12 #1
2 8299
Smygis
126 100+
begin() never calls guess_num().
Feb 13 '12 #2
Okay so that is where I went wrong. Thank you for the help.
Feb 13 '12 #3

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

Similar topics

1
by: Jos | last post by:
Hello all. I have a working server, using the asyncore/chat module, which enables logging in, rooms and private messaging. I've used this framework to make some simple games that only required...
5
by: Kraken | last post by:
Hi, i have a bit of a problem here. I have an assignment to do an animal guessing game using an original database and updating it as the user enters new animals in it. The program enters the file...
10
by: Steve | last post by:
Hi, I've created a Python program that a user enteres one line of text which will then create an acronym from that text. What I want to add to the program is the abilty to rerun this process...
1
by: Rob | last post by:
What is the best way to safely access a companies ERP data (SQL server) from a website that is hosted outside the firewall ?
24
by: Three Headed Monkey | last post by:
write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1))))))) I tried #include <stdio.h> int pow(int n) { int i,power; power=n;
1
by: zanzabar | last post by:
A company wants to implement MIB devices for 24 locations. They are using SNMP protocol and want to manage their SNMP from the corporate location. I was debating if I use SNMPv2? And the assignment...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.