# Feedback on my first Python program- Guess the number

## Recommended Posts

Hello everyone. I am a C++ and a C# programmer but I was bored recently so I decided to play around with Python for a little while. Here is my first Python program which is a simple little guess the number application. Any feedback would be greatly appreciated (Things I did wrong, things I could do better, things that I could have done easier, ect). Here is the code:
import random

def PlayGame(): pass
Guess=0
try:
print
Guess=int(raw_input("Enter a number between 1 and 10: "))
except ValueError:
print
print "Oops not a number! Try Again!"
if Guess&lt;pNum:
print
print "Too Low"
pTries+=1
elif Guess&gt;pNum:
print
print "Too High"
pTries+=1
else:
pTries+=1
print
print "You got it in "+str(pTries)+" tries!"
PA=""
while PA!="y" and PA!="n":
print
PA=raw_input("Play again (y/n): ")
if PA=="y":
PlayGame()
elif PA=="n":
print
print "See you again soon!"
return
else:
print
print "Please enter Y or N"
return

def PlayGame():
print "Welcome to Guess a number!"
Tries=0
mNum=random.randrange(1,10)

PlayGame()
print
print("The End!")
print
print("Created by Donald May")


Any feedback would be great, thanks :).

##### Share on other sites
Your code looks pretty good. Here are two minor recommendations:

1) The first definition of the "PlayGame()" function isn't needed.

2) Instead of using recursion (AskNum calling AskNum calling AskNum...), you might want to use a while loop. I doubt the player would ever fill the stack, but I think it would be a better practice, in this case.

- Mike

##### Share on other sites
Thanks. I didn't even think about the stack, good point.

I originally had a while loop but I replaced it becuase I figured this way would be better.