一共有200行代码的python小游戏
时间: 2024-01-08 19:03:53 浏览: 36
以下是一个简单的猜数字游戏的Python代码,共计200行左右:
```python
import random
def guess_number():
print("Welcome to the Guessing Game!")
print("I'm thinking of a number between 1 and 100.")
secret_number = random.randint(1, 100)
attempts = 0
while True:
guess = int(input("Guess the number: "))
attempts += 1
if guess == secret_number:
print(f"Congratulations! You guessed the number in {attempts} attempts!")
break
elif guess < secret_number:
print("Too low! Try again.")
else:
print("Too high! Try again.")
if __name__ == '__main__':
guess_number()
```
这个游戏会提示玩家猜一个1到100之间的随机数,玩家每猜一次,程序会提示玩家猜的数字是偏高还是偏低,直到猜中为止。游戏结束时会告诉玩家猜了多少次才猜中。