[Tutor] Can't figure out the syntax error!

Joel Goldstick joel.goldstick at gmail.com
Mon Oct 3 18:56:20 CEST 2011


On Mon, Oct 3, 2011 at 12:53 PM, bob gailer <bgailer at gmail.com> wrote:

>  On 9/30/2011 11:55 PM, Anthony Okutsu wrote:
>
> I'm writing a program in which I input a number and the computer has to
> guess it. Every time I try to run the program it highlights the 'while' at
> the beginning of my loop and says 'invalid syntax' but I have no idea why.
> I'll paste a copy of my program below. Why is there a syntax error in my
> while loop?
>
>  import random
>
>  print("\tCan you beat the machine?\n\n")
>
>  a = 0
> b = 101
> tries = 1
> guess = random.randint(a+1, b-1)
> number = int(input("Choose a number between 1 and 100 for CPU to guess:")
>
>  Missing a ) at the end of the above line.
>
> while guess != number:
>     if guess < number:
>         a = guess
>     else:
>         b = guess
>     print(guess)
>     tries += 1
>     guess = random.randint(a+1, b-1)
>
>  print("Your number is... ", guess, "!!!")
> print("And it only took me", tries, "tries. Can you beat me?")
>
>  input("\n\nPress enter key to exit.")
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:http://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> Bob Gailer919-636-4239
> Chapel Hill NC
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
> Good catch Bob!


-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111003/ed91116d/attachment.html>


More information about the Tutor mailing list