[Tutor] High Low Game
Hi, I am new to Python, and have hit a WALL. Any help is appreciated! Below is what I have so far, for the "High Low Game"...when I try to run it, nothing happens, so I have been unable to finish it. I am sure it is something simple... #assignment 2 part 1 high low def main(): print " Pick a number between 1 and 1000 and I will try to guess it" print "in no more than 10 tries. After each guess, enter 0 if I" print "got it right, -1 if I need to guess lower, and 1 if I need to" print "guess higher." high=1000 low=1 tries=1 while high > low: ave=(high+low)/2 print "My guess is", ave, guess=int(raw_input("Please enter '-1','0',or '1'):")) print guess if guess == 0: print "That took 1", tries, "guesses." elif guess == -1: print "I will guess lower." elif guess == 1: print "I will guess higher." else: print "Pick a number between 1 and 1000 and I will try to guess it" print "in no more than 10 tries. After each guess, enter 0 if I" print "got it right, -1 if I need to guess lower, and 1 if I need to" print "guess higher." main() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] pydoc?
Hi all, Below is part of an email I got from someone in reply to a question about a program called brlapi. I am on Windows. Can someone explain what is going on here? > Hmm... I am relatively new to Python and have not found this pydoc. Well, I don't know how this is supposed to work on Windows. On Linux, you simply run pydoc brlapi in a shell. Alternatively, you can have a look in brltty's source code, in Bindings/Python/brlapi.pyx, which is the source for that pydoc. -- Have a great day, Alex (msg sent from GMail website) mehg...@gmail.com; http://www.facebook.com/mehgcap ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] High Low Game
On Mon, Oct 18, 2010 at 6:34 PM, Raquel wrote: > Hi, > I am new to Python, and have hit a WALL. Any help is appreciated! Below > is what I have so far, for the "High Low Game"...when I try to run it, > nothing happens, so I have been unable to finish it. I am sure it is > something simple... > #assignment 2 part 1 high low > def main(): > print " Pick a number between 1 and 1000 and I will try to guess it" > print "in no more than 10 tries. After each guess, enter 0 if I" > print "got it right, -1 if I need to guess lower, and 1 if I need to" > print "guess higher." > high=1000 > low=1 > tries=1 > while high > low: > ave=(high+low)/2 > print "My guess is", ave, > guess=int(raw_input("Please enter '-1','0',or '1'):")) > print guess > if guess == 0: > print "That took 1", tries, "guesses." > > elif guess == -1: > print "I will guess lower." > elif guess == 1: > print "I will guess higher." > else: > print "Pick a number between 1 and 1000 and I will try to guess > it" > print "in no more than 10 tries. After each guess, enter 0 if I" > print "got it right, -1 if I need to guess lower, and 1 if I need > to" > print "guess higher." main() > move main() outside the while loop. This will get the car started, but haven't looked for other flaws in the engine > > > > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] High Low Game
More importantly, outside the function it calls. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] High Low Game
"Raquel" wrote I am new to Python, and have hit a WALL. Any help is appreciated! Below is what I have so far, for the "High Low Game"...when I try to run it, nothing happens, so I have been unable to finish it. I am sure it is something simple... First some questions: 1) What OS are you using? 2) What version of Python 3) How are you trying to run the program? 4) When you say "nothing happensd" is that absolutely true? Is anything displayed, even fleetingly? Second, some comments on your code: def main(): print " Pick a number between 1 and 1000 and I will try to guess it" print "in no more than 10 tries. After each guess, enter 0 if I" print "got it right, -1 if I need to guess lower, and 1 if I need to" print "guess higher." You could do this with a single print statement and a triple quoted string. And if you made it a variable you wouldn't even need a function, just print the prompt message: prompt = """ Pick a number between 1 and 1000 and I will try to guess it in no more than 10 tries. After each guess, enter 0 if I got it right, -1 if I need to guess lower, and 1 if I need to guess higher. """ print prompt high=1000 low=1 tries=1 while high > low: ave=(high+low)/2 print "My guess is", ave, Your guesses will always be the same since you never change high or low... For the same reason you will never exit the while loop. guess=int(raw_input("Please enter '-1','0',or '1'):")) print guess if guess == 0: print "That took 1", tries, "guesses." I don't think you want the 1 in there. tries should suffice? Also you might want to force an exit from the while loop here? elif guess == -1: print "I will guess lower." elif guess == 1: print "I will guess higher." Nice promise but you only ever guess lower. You need to move the guess creation code into the appropriate if/else block. else: print "Pick a number between 1 and 1000 and I will try to guess it" print "in no more than 10 tries. After each guess, enter 0 if I" print "got it right, -1 if I need to guess lower, and 1 if I need to" print "guess higher." You don't need this since you print it in the next line anyway! main() This could become the "print prompt" line... While there are flaws in the logic it looks like it should work after a fashion, aso that brings me back to the question of how you are running it?. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pydoc?
"Alex Hall" wrote about a program called brlapi. I am on Windows. Can someone explain what is going on here? Hmm... I am relatively new to Python and have not found this pydoc. Well, I don't know how this is supposed to work on Windows. On Linux, you simply run pydoc brlapi pydoc lives in C:\PythonXX\Tools\scripts And the best way to run it is probably to use the GUI so cd to the folder and run python pydocgui.pyw Or create a shortcut to do the same... Basically it will provide you with a prettified web version of the help() output! For that reason I tend not to use it much... YMMV HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Learning with Open Source Applications.
Hello all. I am sorry for the cross posting but I really would like to hear comments from experience people in Python. I am new to Python, not new in programming. I am leaving the PHP path and moving to Python. When I was learning PHP it was very useful to learn to install OpenSource solutions , implemented them and study how they work, learn how to modify them. For example I used e-commerce shopping cart solution and learned a lot. Can you recommend, similar solutions, not only for shopping cart but any other subject is good also so I can follow the same schema of learning ? I mean, solutions you consider are very well written and that are examples of what a good Python applications should be written? I know there are tons of applications but would like to hear advice based on experience if possible. Thanks. Thanks in advance. Jorge Biquez ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor