On Mon, Oct 3, 2011 at 12:53 PM, bob gailer <[email protected]> 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 - [email protected]
> To unsubscribe or change subscription
> options:http://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> Bob Gailer919-636-4239
> Chapel Hill NC
>
>
> _______________________________________________
> Tutor maillist - [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
> Good catch Bob!
--
Joel Goldstick
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor