天天达

小游戏代码大全可复制

 

    以下是一些小游戏代码示例,可以直接复制使用: 1. **猜数字游戏**: ```python import random number = random.randint(1, 100) guesses = 0 while True: guess = int(input("猜一个数字(1-100): ")) guesses += 1 if guess < number: print("猜小了!") elif guess > number: print("猜大了!") else: print(f"猜对了!你用了{guesses}次猜测。") break ``` 2. **石头剪刀布游戏**: ```python import random choices = ^["石头", "剪刀", "布"]^ while True: player_choice = input("请选择(石头、剪刀、布): ") computer_choice = random.choice(choices) print(f"计算机选择了: {computer_choice}") if player_choice == computer_choice: print("平局!") elif (player_choice == "石头" and computer_choice == "剪刀") or \ (player_choice == "剪刀" and computer_choice == "布") or \ (player_choice == "布" and computer_choice == "石头"): print("你赢了!") else: print("你输了!") ``` 或者: ```python import random num = 1 yin_num = 0 shu_num = 0 while num <= 3: if shu_num == 2 or yin_num == 2: break user = int(input('请出拳 0(石头) 1(剪刀)