Python乱写脚本
#该脚本适用于Python 3.x版本
import random
games = ['猜数字', '拍扁蚊子', '捉迷藏']
while True:
choice = input("请选择一项游戏: ")
if choice == 'exit':
break
elif choice not in games:
print("请重新选择!")
else:
print("你选择了玩{}".format(choice))
for i in range(5):
print("正在准备游戏...")
print("游戏开始!")
if choice == '猜数字':
ans = random.randint(1,100)
guess = -1
count = 0
while guess != ans:
guess = int(input("请猜一个1-100内的数: "))
count += 1
if guess > ans:
print("猜大了!")
elif guess < ans:
print("猜小了!")
else:
print("猜对了!")
print("你猜了{}次。".format(count))
elif choice == '拍扁蚊子':
score = 0
for i in range(10):
mos = random.randint(1,2) #生成蚊子的横坐标
height = random.randint(1,20) #生成蚊子的高度(可以手动调节)
print("\n" * height, " "* mos, "@", end="")
print("\n" * (20 - height), end="") #保证蚊子卡在顶部不跑
input_j = input("给我一个J:") #让用户按J把蚊子打扁
if input_j == "J":
score += 1
print("你紧接着又扁了一个蚊子,当前得分{}分。".format(score))
else:
print("SKR打错啦!本次得分{}分。".format(score))
else:
print("该游戏还在开发中...")
下载地址
用户评论