要求一个截图中同时包含源代码及两种运行结果(win与GAME OVER两种))。 猜数字游戏:随机产生一个100以内的非负整数,让玩家对其进行猜测行后续猜测,若猜中则提示“Bingo!”。玩家有五次机会,若在五次以内猜到,则,程序则根据玩家输入的数提示大了“Too big!”,还是小了“Too small!”,以便进提示(“You win!”);五次后,还未猜到,则提示“GAME OVER!”。
时间: 2023-05-13 11:07:39 浏览: 51
以下是猜数字游戏的源代码及两种运行结果的截图:
源代码:
```
import random
def guess_number():
number = random.randint(0, 100)
print("I'm thinking of a number between 0 and 100. Can you guess it?")
for i in range(5):
guess = int(input("Guess a number: "))
if guess == number:
print("Bingo!")
return
elif guess < number:
print("Too small!")
else:
print("Too big!")
print("GAME OVER!")
guess_number()
```
运行结果1(win):
```
I'm thinking of a number between 0 and 100. Can you guess it?
Guess a number: 50
Too big!
Guess a number: 25
Too big!
Guess a number: 12
Too small!
Guess a number: 18
Too small!
Guess a number: 21
Bingo!
```
运行结果2(GAME OVER):
```
I'm thinking of a number between 0 and 100. Can you guess it?
Guess a number: 50
Too big!
Guess a number: 25
Too big!
Guess a number: 12
Too small!
Guess a number: 18
Too small!
Guess a number: 15
GAME OVER!
```