用python写猜数字要求用到easygui库,全部要求为英语
时间: 2023-04-12 17:01:00 浏览: 99
猜数字python代码
Sure, I can answer your question. Here is an example code for a number guessing game using the easygui library in Python:
```
import random
import easygui
secret_number = random.randint(1, 100)
guess = 0
tries = 0
easygui.msgbox("I'm thinking of a number between 1 and 100. Can you guess it?")
while guess != secret_number:
guess = easygui.integerbox("Enter your guess:", lowerbound=1, upperbound=100)
if guess is None:
break
tries += 1
if guess < secret_number:
easygui.msgbox("Too low! Try again.")
elif guess > secret_number:
easygui.msgbox("Too high! Try again.")
else:
easygui.msgbox("Congratulations! You guessed the number in " + str(tries) + " tries.")
```
I hope this helps!
阅读全文