from random import * # original guessing game # problem: after winning you still have to guess # problem: always the same number # number of guesses is limited -- would be nice to let user # guess until they have it def guessing_game(guesses, toguess): print("I'm thinking of a number between 0 and 100...") for i in range(guesses): guess = int(raw_input("Your guess? ")) if(guess < toguess): print("Too low!") elif(guess > toguess): print("Too high!") else: print("You're right!") def guessing_game1(): print("I'm thinking of a number between 0 and 100...") guess = -1 # a value to get the loop going toguess = randint(0, 100) while(toguess != guess): guess = int(raw_input("Your guess? ")) if(guess < toguess): print("Too low!") elif(guess > toguess): print("Too high!") else: print("You're right!") #guessing_game(5, 10) guessing_game1() # Gets a number from a user and squares it until the user types -1 to exit user = 0 #while(user > 0) would also work while(user != -1): user = int(raw_input("Give me a number (-1 to exit) ")) print(user * user) def treasure_hunt(): up() x = randint(-200, 200) y = randint(-200, 200) goto(x, y) down() color("yellow") fill(True) circle(10) fill(False) color("black") circle(10) print(xcor()) up() goto(0, 0) down() print(xcor()) print(x) # while the turtle's x value is not equal to x and # the y value is not equal to y # then goto a random position # coin is at 0, 0 # 3, 4 # 5, 7 # 5, 8 # 0, 4 while(not(xcor() == x and ycor() == y)): goto(randint(-200, 200), randint(-200, 200))