break the loop in one object and then return

Petr Jakes petr at
Tue Jun 27 09:22:51 CEST 2006

Alex Pavluck wrote:
> Peter,  Why do you make such claims without any reason to do so?  This
> is my own thing.  So, I guess I am a student but just a student of my
> own accord.  So, please don't reply if you don't have anything to
> contribute.
This is not "YOUR OWN THING". This group really can help, but this
group AFAIK does not write homeworks. It is nothing wrong you are just
a student, we are all students somehow :)

Few other posters were posting similar requests to this group last few
days (maybe your classmates :)) so the chance it just a coincidence is
very low. If I am wrong, sorry about that.

This group can help, but some effort (study, googling this group etc.)
on your side is necessary as well. Other posters suggested you the way,
where to go, but you didn't try to change your code a bit. Please read
the following as well:

To your code:
> As for the - mynum I guess that could happen but I am just doing this
> so that they will never match on first try.  I guess I should just
> hardcode it.
> This is what happens if I step though:
> mynum = 93    ***1***

use # sign for your comments in the code followed by the comment text.
All the stuff after the # is ignored when the code is executed. Nobody
can execute (examine) your code whit your comments like ***1***

To hardcode "mynum" value is IMHO very bad idea and your code will be
useless if the value will be "discovered". Other suggested how to
generate random number at the beginning of the code.

> yournum = input("I am thinking of a number between 1 and 100.\n  Guess
> which number: ")   ***2***
> def strt():  ***3***    ***6***
>     if yournum == mynum:     ***7***
>         print "Wow!  You got it!"
>     elif yournum < mynum:  ***8***
>         print "Nope.  Too low"   ***9***
>         again()                        ***10***  ***15***
>     elif yournum > mynum:
>         print "Oh, your too high"
> def again(): ***4*** ***11***
>     global yournum   ***12***
>     yournum = input("guess again: ")  ***13***
>     strt()  ***14***
> strt()  ***5***
> ***15***  is the problem.  It doesn't start at the top but rather where
> is leaves the loop.

print statement can help to solve your problem, put it (with some text
that will navigate you) on the rows where you are not sure the program
is not running properly. Print out the values of the mynum and yournum
as well. This will be just for your "debugging" purposes. Finally you
will remove it.

For example you can put:
print "starting the strt function", "mynum = ", mynum, "yournum =",

on the first row of your strt function, so you will see the code is
going through there.

Try to thing what will happen if the person will input character rather
than integer.

Again: good luck in your effort

Petr Jakes
> Petr Jakes wrote:
> > It smells like many student are trying to do their homework last few
> > days here ... Can we now the name of your school? :)
> >
> > AFAIK this group does not solve homeworks here :)
> >
> > Just few points:
> >
> > at the beginning try to test the input value
> > you can use "in range" or using "0 < yournum  < 101"
> >
> > you should test if the input is an integer as well..
> >
> >
> > Other suggested here which way to go.
> > 
> > Good luck :)
> > 
> > Petr Jakes

More information about the Python-list mailing list