import random
def guessNum():
correctNum = random.randint(1,100)
guess = 0
tries = 0
min = 1
max = 100
while guess != correctNum and tries < 6:
print("Guess my thinking number(",min,"~",max,"): ")
print("now you got",(6-tries),"chances left")
tempNum = input()
guess = int(tempNum)
print("Your guess is", guess, "...")
if guess < correctNum:
print("my number is Bigger than", guess)
min = guess + 1
elif guess > correctNum:
print("my number is Smaller than", guess)
max = guess - 1
tries += 1
if guess == correctNum:
print("Yes!",correctNum,"That's my thinking number!")
print("you find my number in", tries)
newGame()
else:
print("No, You are out of chances.")
print("my thinking number is", correctNum)
newGame()
def newGame():
sel = input("Do you want to play another game?(y/n)")
if sel == "y":
print("-----------------------------------")
guessNum()
else:
print("then play another time. bye~")
guessNum()
|