Hey! I am Eagle.今天我花了半个小时制作了一个剪刀石头布。哪位大佬帮我康康哪里可以简化?我觉得我写的非常的烂全是if
我也不会做注释,大佬指导指导
"""
@author: Eagle
@contact: 2170257193qq.com
@software: PyCharm
@file: 石头剪刀布.py
@time: 2021/8/6 下午9:35
@desc:
"""
import random
import time
times = 0
win = 0
lose = 0
print("""
1 为石头
2 为剪刀
3 为布
三局两胜,来不开始吧!
AI:我已经迫不及待了!
""")
while True:
AI = str(random.randint(1,3))
player = str(input("请输入:"))
if player == "1" or player == "2" or player == "3":
print("等待AI(3秒)……")
time.sleep(3)
times += 1
if AI == "1":
AI1 = "石头"
elif AI == "2":
AI1 = "剪刀"
else:
AI1 = "布"
print("AI=我出的是:",AI1)
if player == AI:
print("平局")
elif player == "1":
if AI == "2":
print("AI:你赢了")
win += 1
else:
print("AI:你输了")
lose += 1
elif player == "2":
if AI == "3":
print("AI:你赢了")
win += 1
else:
print("AI:你输了")
lose += 1
else:
if AI == "1":
print("AI:你赢了")
win += 1
else:
print("AI:你输了")
lose += 1
else:
print("""
1 为石头
2 为剪刀
3 为布
三局两胜,来不开始吧!
AI:我已经迫不及待了!
""")
print("请输入(1-3):")
if times == 3:
if win >= 2:
print("AI:我承认你赢了,但是我下次一定会赢回来了")
else:
print("AI:切!你输了!!!")
a = str(input("继续请按q"))
if a == "q":
print("AI:来吧")
else:
break
print("AI:继续")
print("AI:下次再战")
|