Python案例:石头剪刀布练习

Python案例:石头剪刀布练习,第1张

如下图:

实例结果:

代码如下:

import random
 
c1=0
c2=0
while True:
    j=random.choice(["剪刀","石头","布"])
    a=input("你出的是(输入e退出):")
    if a=="e" or a=="E":
        break
    elif a==j:
        print(f"电脑出的是:{j}\n平局")
    elif (a=="石头" and j=="剪刀") or (a=="剪刀" and j=="布") or (a=="布" and j=="石头"):
        print(f"电脑出的是:{j}\n玩家胜")
        c1+=1
    elif (j=="石头" and a=="剪刀") or (j=="剪刀" and a=="布") or (j=="布" and a=="石头"):
        print(f"电脑出的是:{j}\n电脑胜")
        c2+=1
print("游戏结束")
print(f"你的得分:{c1}")
print(f"电脑得分:{c2}")
 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/739047.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-28
下一篇 2022-04-28

发表评论

登录后才能评论

评论列表(0条)

保存