宇宙之一粟
目录
1、猜数字游戏
2、猜拳游戏
一、伪代码格式:
二、正确代码格式:
import random
import sys
computer = random.randint(0, 100)
print(computer)
while True:
guss = int(input("请输入一个0~100以内的整数:"))
if computer == guss:
print("恭喜您,猜对了")
guss = input("是否继续(Y/N):")
if guss == "N" or guss == "n":
sys.exit("欢迎下次再来")
else:
computer= random.randint(0, 100)
elif guss > computer:
print("猜大了")
else:
print("猜小了")
import random
computer =random.randint(0,2)
print(f"随机生成的数是{computer}")
print("提示:拳头(0),剪刀(1),布(2)")
index = int(input("请出拳头(0),剪刀(1),布(2):"))
if(index == 0 and computer==1)or(index ==1 and computer==2)or(index== 2 and computer == 0):
print("恭喜你,获得了胜利")
elif(index == computer):
print("平局")
else:
(index == 0 and computer==2)or(index ==1 and computer==0)or(index== 2 and computer == 1)
print("你输了")
# 初始化表示手势的变量
gesture = ['石头' , '剪刀', '布']
wins = 0
# 进行5轮游戏
for i in range(5):
# 输入玩家的手势
print("0:石头 1:剪刀 2:布")
print("\t*********\t")
user = int(input("请输入你想出的序号:"))
if(user >= 0 and user <= 2):
computer = random.randint(0, 2)
print(f"玩家: {gesture[user]}, 计算机: {gesture[computer]}")
if user == computer:
print("...平局! ")
elif computer == (user + 1) % 3:
print("...玩家获胜! ")
wins = wins + 1
else:
print("...计算机获胜! ")
else:
print("\t你输入的序号有错、请重新输入!\t")
print(f"玩家获胜次数: {wins}")