![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Nov 2007
Posts: 61
Rep Power: 1
![]() |
My pyguessinggame
Could someone look this over
#import whrandom
def start():
answer=randint(1,101) #the answer
guessnum=0 #number of user guesses
guess=raw_imput ('guess my number, it is between 1 and 100') #user's guess
while guess!= answer:
guessnum=guessnum+1
if(guess <= 0):
print '''My number is between 1-100, you gave a negative just to see what I would say.'''
elif (guess >= 101):
print'no the answer is below 101'
elif (guess > answer):
print 'Too high'
elif (guess<answer):
print 'guess higher, your guess is too low'
else:
print 'Right on, congratualations that took', guessnum, 'tries.'
#I truly don't understand from here to.............
if _neame_ =='_main_':
start():
print
raw_imput('press return')
else:
print 'Module guessgame imported'
print 'to run, type:guessgame.start()'
print 'to refreash, type:reload (guessgame)'
#.....here
#end
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,725
Rep Power: 5
![]() |
Re: My pyguessinggame
I really don't understand how your code could possibly have so many syntax mistakes, yet be code that you've written at the same time. Were you writing this out by hand or something??
Some of the most notable mistakes:
Finally, all of your indentation is completely and utterly wrong. I'm tired of being someone's IDE. These are syntax mistakes. If you're making this many mistakes, then you don't yet understand how to work with Python. You need to learn to follow tutorials carefully, experiment for yourself, and you need to learn how to read the errors shown by the Python Traceback. Fixing all of these mistakes makes the code executable. But it still does not work as required, because the logic of the script is incorrect. I'm not fixing that part for you. from random import *
def start():
answer=randint(1,101) #the answer
guessnum=0 #number of user guesses
guess=raw_input ('guess my number, it is between 1 and 100') #user's guess
while guess!= answer:
guessnum=guessnum+1
if(guess <= 0):
print '''My number is between 1-100, you gave a negative just to see what I would say.'''
elif (guess >= 101):
print'no the answer is below 101'
elif (guess > answer):
print 'Too high'
elif (guess<answer):
print 'guess higher, your guess is too low'
else:
print 'Right on, congratualations that took', guessnum, 'tries.'
#I truly don't understand from here to.............
if __name__ == '__main__':
start()
print
raw_input('press return')
else:
print 'Module guessgame imported'
print 'to run, type:guessgame.start()'
print 'to refreash, type:reload (guessgame)'
#.....here
#end |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Nov 2007
Posts: 61
Rep Power: 1
![]() |
Re: My pyguessinggame
Yes I was writting it out by hand, I am sorry for the spelling mistakes, and you don't need to help me if you don't want, i don't understand how you can say you are getting tired of fixing others mistakes like this yet you do it anyways. Please do not feel obligated to help me. I am a newbie and I adapted a "warmer/colder" game to try to get this to work.
The main problem I had was I couldn't make an "IF" statement follow several different parameters eg.) If guess is >0 AND <=100 AND > answer:
print ' too low'I also copied some things from an old Python book, so that is the reason for some of the mistakes Finaly I copied the end part that I noted I didn't understand and just switched out some names and variables. And about the "#import whrandom" mistake I copied wrong off the paper it was supposed to read #guessgame.py by ******************* (1/20/08) import whrandom * but it is wrong anyways
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Last edited by Chuckiferd; Jan 20th, 2008 at 3:09 PM. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,725
Rep Power: 5
![]() |
Re: My pyguessinggame
Yes. I'm getting tired of it, but that doesn't mean I won't help you. I don't want to be the one who ignores you based on inability to code. We all started somewhere, and so you don't deserve that. I just wish you put a bit of effort into trying to fix the syntax errors.
In reference to your last post's code: eg.) If guess is >0 AND <=100 AND > answer:
print ' too low'You can get an "if" statement to work that way, like so: Python Syntax (Toggle Plain Text)
The main thing you were missing is you have to include the variable 'guess' for each relationship. Python can't just assume what variable you want to use for the next relationship. Note, the brackets aren't necessary. It's just to help show how the statement is broken up. But as for the logic of your program, it's stuck in an infinite loop, because you don't keep asking the user for a new number. You only ask him once. That's one of your problems. |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Nov 2007
Posts: 61
Rep Power: 1
![]() |
Re: My pyguessinggame
it was as simple as that
!!!!!, I didn't think I was actually correct with the 'and' statement. Well now I can re-write the whole thing like I originaly intended to do instead of using someone elses code as a model. I can get this to work, I will resubmit it once I get it done.
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Nov 2007
Posts: 61
Rep Power: 1
![]() |
Re: My pyguessinggame
I am attempting to write the program from scratch right here on the computer
#guessgame********** (1/20/08)
from whrandom import randint
def start():
answer=randint(1,101) #the answer
guessnum=1 #number of failed user guesses
guess=raw_imput('''I am thinking of a number that is in between 1 and 100''')#the current guess of the user
while guess != answer:
guessnum=guessnum+1
if guess > 100
print '''that guess is way too high, the answer has to be 100 or lower'''
guess=raw_imput('guess again please, within the limit this time')
elif guess = 0
print 'actually zero is not within the 1-100 range'
guess=raw_imput('guess again please')
elif guess < 0
print 'are you testing me?'
guess=raw_imput(guess again, in the positives please')
elif guess > 0 and guess < 100 and guess < answer
print 'that guess is below the answer'
guess=raw_imput('try guessing again')
elif guess >0 and guess < 100 and guess > answer
print 'guess lower, your answer is to high'
guess=raw_imput('try once more')
elif guess == answer
print 'congratualtions, that took', guessnum, 'tries'
#would I need a 'break command here? or maybe a 'sys.exit()'
new_line
#I still don't understand this part.....
if __name__ == '__main__':
start()
print
raw_input('press return')
else:
print 'Module guessgame imported'
print 'to run, type:guessgame.start()'
print 'to refresh, type:reload (guessgame)'
#--------------------------------------------------------------------
#.....to this part, please explain, I copied it out of another program,
#simply switching out 'warmer' and 'run' with 'guessgame' and 'start'
#--------------------------------------------------------------------
#end game
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Last edited by Chuckiferd; Jan 20th, 2008 at 7:10 PM. |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Nov 2007
Posts: 61
Rep Power: 1
![]() |
Re: My pyguessinggame
seeing how nobody has said anything I am going to guess It is fine (or its so bad everybody has givin up on me
)
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#8 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,725
Rep Power: 5
![]() |
Re: My pyguessinggame
It's still very incorrect in many ways, but at least if you had Python you seem to have enough potential to fix it. Just get a Python interpreter working on your computer, seriously. :/
|
|
|
|
|
|
#9 |
|
Programmer
Join Date: Nov 2007
Posts: 61
Rep Power: 1
![]() |
Re: My pyguessinggame
Will do (once I erase that laptop XP operating system off my 98 desktop
) then I should be fine, but the computer won't let me past the log in screen (slaps head) Why did I reformat the computer Why! Why! Why!
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#10 |
|
Expert Programmer
|
Re: My pyguessinggame
It's not worth other people's time to fix mistakes in your code that a compiler could easily catch. Until you have a working compiler I suggest you refrain from asking others if your code works.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|