[Tutor] What's the invalid syntax?
Nathan Pinno
falcon3166 at hotmail.com
Thu Aug 24 06:27:13 CEST 2006
Sorry, but it only showed a text-box with the message "Invalid syntax!",
then highlighted the %.
HTH,
Nathan Pinno
----- Original Message -----
From: "Alan Gauld" <alan.gauld at freenet.co.uk>
To: "Nathan Pinno" <falcon3166 at hotmail.com>; "Tutor mailing list"
<tutor at python.org>
Sent: Wednesday, August 23, 2006 10:10 PM
Subject: Re: [Tutor] What's the invalid syntax?
>
>> What's the invalid syntax in the following code?
>
> Dunno, Where does Python think it is?
> In other words what does the error message/IDE say?
> Give us a clue....
>
> Alan G.
>
>
> ########################
>
>
> # Hurkle Hunt
> # This program is a game where you have to find a hurkle that the computer
> hides in a grid.
> # Originally in Computer World pg. 70
>
> import random
>
> print "Hunt the Hurkle"
> print
> while 1:
> ans = raw_input("Do you want to play a game? Type Y to play, any other
> letter to quit.")
> while ans == "y" | ans == "Y":
> E = random.choice(range(9))
> N = random.choice(range(9))
> k = 1
> while k <= 5:
> print "Guess ", %d1.0, "."(k)
> X = int(raw_input("East Guess: "))
> Y = int(raw_input("North Guess: "))
> if X > E & Y == N:
> print "Go West"
> k = k + 1
> elif X > E & Y > N:
> print "Go SouthWest"
> k = k + 1
> elif X > E & Y < N:
> print "Go NorthWest"
> k = k + 1
> elif X == E & Y > N:
> print "Go South"
> k = k + 1
> elif X == E & Y < N:
> print "Go North"
> k = k + 1
> elif X < E & Y == N:
> print "Go East"
> k = k + 1
> elif X < E & Y > N:
> print "Go SouthEast"
> k = k + 1
> elif X < E & Y < N:
> print "Go NorthEast"
> k = k + 1
> else:
> print "Congrats! You found the hurkle in", %d1.0, "
> guesses!" (k)
> break
> else:
> print "You didn't find the hurkle in 5 tries! It was at: ", E,
> ",", N
> break
> else:
> break
> print "Goodbye!"
> break
>
> Thanks!
> Nathan Pinno
>
More information about the Tutor
mailing list