猫史档案馆


【Python作品分享】石头剪刀布

用户:_韩佳霖_韩佳霖查看:0 回复:0 评论:0 创建时间:2021-05-03T22:03:00


【作品展示】

center_image

 

【作品介绍】

石头剪刀布

 

【作品源代码】

from time import *
import random
person_win = 0
computer_win = 0
draw = 0
a = 1
b = 1
i = 0
choices = [2,5,0]
while(a != 6):
    i = i + 1
    print("请输入 2(剪刀) 或 5(布) 或 0(石头) 或 6(退出) , [ 注 : 只能选 2 , 5 , 0 , 6 !!! ]")
    a = int( input() )
    b = random.choice(choices)
    print("你 :", a)
    print("电脑 :",b)
    print("\n")
    if a == b:
        print("- 平局")
        draw = draw + 1
    elif a == 5:
        if b == 0:
            print("- 你赢了")
            person_win = person_win + 1
        else:
            print("- 电脑赢了")
            computer_win = computer_win + 1
    elif a == 2:
        if b == 5:
            print("- 你赢了")
            person_win = person_win + 1
        else:
            print("- 电脑赢了")
            computer_win = computer_win + 1
    elif a == 0:
        if b == 2:
            print("- 你赢了")
            person_win = person_win + 1
        else:
            print("- 电脑赢了")
            computer_win = computer_win + 1
    elif a == 6:
        print("\n\n\n\n\n\n\n\n\n\n")
        print("你赢了",person_win,"次")
        print("电脑赢了",computer_win,"次")
        print("平局了", draw, "次")
        if i > 1:
            win = person_win / (i - 1)
        else:
            win = 0
        print("胜率 :%.2f" % win)
        sleep(3.5)
        print("                                                    .-- -- -- -- -- Exit -- -- -- -- --.     ")
    else:
        print("error -- Input wrong  or  Bug")
    print("\n\n")
sleep(5)
'''

大作   用了57行代码 + 注释5行   时间 : 2021.05.02 20:03 ~ 2021.05.02 23:16  +  2021.05.03 21:02 ~ 2021.05.03 22:04

'''

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页