![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Programmer
Join Date: Nov 2007
Posts: 64
Rep Power: 1
![]() |
Re: My pyguessinggame
All right I won't do it anymore,
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#12 |
|
Programmer
Join Date: Nov 2007
Posts: 64
Rep Power: 1
![]() |
Re: My pyguessinggame
I have one last quick question, Sane you talked about how the logistics are wrong. Seeing how I still stuck to the form of the 'warmer' game by the way here it is in an indented version, in the book they did not indent (to save space?)
I see several syntax errors but I want to know if their are still sematic and/or simple logistic errors errors. Please don't point them out I am trying to learn, but a Yes or No answer would be nice Don't worry I will have a Python interpreter on my computer any time now so If their is syntax errors I will rat them out myself when it doesn't work.
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#13 |
|
Programming Guru
![]() |
Re: My pyguessinggame
The only noticeable logical mistake I can find is you won't see the result of how many tries it took. Can you see why?
After you fix that, and the slew of syntax errors, it should be perfect actually. ![]() Edit: You were also wondering what this was all about: 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)'The line if __name__ == '__main__' holds true if you are executing the script as the main file.This is opposed to "importing" the script, the same way you import random. Random is simply a script, called random.py, that you're importing for use. In this case, your script is the "main" file, and "random.py" is not.So if someone were to import your script, they would get the message: Module guessgame imported to run, type:guessgame.start() to refresh, type:reload (guessgame) Because the statement if __name__ == '__main__' is not satisfied, since your program is no longer the 'main' file. The file that imported yours is the 'main' file. And they can use your script the same way your script uses random.py. Understand? |
|
|
|
|
|
#14 |
|
Programmer
Join Date: Nov 2007
Posts: 64
Rep Power: 1
![]() |
Re: My pyguessinggame
I get it now
Does this correct the mistake with the feedback on the amount of tries print 'Congrats, that took', guessnum ,'tries' As compared to print 'Congrats, that took', guessnum, 'tries' Seeing as 'guessnum' and 'guessnum,' could be interpreted as different variables
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#15 |
|
Programming Guru
![]() |
Re: My pyguessinggame
Nope. It makes no difference. If it did, I'd consider it a syntax error anyways. Your error is a logic error, regarding program flow (which lines execute in which order).
|
|
|
|
|
|
#16 |
|
Programmer
Join Date: Nov 2007
Posts: 64
Rep Power: 1
![]() |
AHAH!!!, I thought you said that it wouldn't work, but it is actually inacurate, the note says number of failed user guesses , yet I made it start at 1. I would rather have it represent number of user guesses than failed guesses.
Finally enough with that, I found that problem AND another one. Firstly, the 'elif' loop containing 'guess == answer' I forgot to add to the 'guessnum' variable Secondly, the one you didn't find. The majority of the program is in a While guess != answer meaning when guess IS equal to answer that the computer will skip over the instructions I set
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#17 |
|
Programming Guru
![]() |
Re: My pyguessinggame
Now you're just jumping all over the place... You are straying further away from what you need to correct.
Everything was correct, except one thing regarding program flow. I've even tested it to make sure I was right. And this being pretty primitive Python, juxtaposed to years of experience with Python, I was as correct as I initially asserted. I'll say one thing, you are getting close with your thought regarding guess != answer. But there's only one thing you need to change, and it's not that. |
|
|
|
|
|
#18 |
|
Programmer
Join Date: Nov 2007
Posts: 64
Rep Power: 1
![]() |
Re: My pyguessinggame
but while the terminating secquence of the program is in a While loop it doesn't correspond to it will never be reached. Just like
while a=1
print a
if a = 2
print 'this never will be printed'
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
|
|
#19 |
|
Programming Guru
![]() |
Re: My pyguessinggame
Again, not entirely true.
a = 1
while a == 1:
a = input("A? ")
if a != 1:
print "Did this just happen?"If the user enters the value 2 into the prompt, he/she will get the message: Did this just happen?. The while loop condition is only tested before it wraps back around to the top. But we digress further from the problem. It's not your while loop, and it's not the number of guesses. It's the placement of where you decide to print the result that suffers as a result of your program flow. You don't want it inside the while block. It's not part of the while logic. Get er' out of there! |
|
|
|
|
|
#20 |
|
Programmer
Join Date: Nov 2007
Posts: 64
Rep Power: 1
![]() |
Re: My pyguessinggame
Isn't that what I was saying, oh well, I got an interpreter up, even though I can't figure out how to run the program, the $ is not working and neither is plain typing in the programs name
![]() Oh yeah I am getting tons of indentation errors, no clue why though
__________________
There are 10 kinds of people in this world, those who can read binary and those who can't. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|