Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 21st, 2008, 5:37 PM   #11
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
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.
Chuckiferd is offline   Reply With Quote
Old Jan 21st, 2008, 8:19 PM   #12
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
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.
Chuckiferd is offline   Reply With Quote
Old Jan 21st, 2008, 8:26 PM   #13
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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?
Sane is offline   Reply With Quote
Old Jan 22nd, 2008, 10:52 AM   #14
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
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.
Chuckiferd is offline   Reply With Quote
Old Jan 22nd, 2008, 11:29 AM   #15
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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).
Sane is offline   Reply With Quote
Old Jan 22nd, 2008, 3:18 PM   #16
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
Talking Re: My pyguessinggame

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
loop

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.
Chuckiferd is offline   Reply With Quote
Old Jan 22nd, 2008, 3:27 PM   #17
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Jan 22nd, 2008, 3:55 PM   #18
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
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.
Chuckiferd is offline   Reply With Quote
Old Jan 22nd, 2008, 4:02 PM   #19
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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!
Sane is offline   Reply With Quote
Old Jan 23rd, 2008, 10:15 AM   #20
Chuckiferd
Programmer
 
Join Date: Nov 2007
Posts: 64
Rep Power: 1 Chuckiferd is on a distinguished road
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.
Chuckiferd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC