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

bob gailer bgailer at gmail.com
Mon Oct 3 18:53:34 CEST 2011


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 Gailer
919-636-4239
Chapel Hill NC

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111003/6272c214/attachment-0001.html>


More information about the Tutor mailing list