精华内容
下载资源
问答
  • 主要为大家详细介绍了python石头剪刀布小游,三局两胜制,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • Python 石头剪刀布小游戏(三局两胜) import random all_choioces = ['石头', '剪刀', '布'] win_list = [['石头', '剪刀'], ['剪刀', '布'], ['布', '石头']] poeple_on = True poeple_add = 0 compute_add =0 ...

    Python 石头剪刀布小游戏(三局两胜)

    import random
    all_choioces = ['石头', '剪刀', '布']
    win_list = [['石头', '剪刀'], ['剪刀', '布'], ['布', '石头']]
    poeple_on = True
    poeple_add = 0
    compute_add =0
    while poeple_on:
        compute = random.choice(all_choioces)
        put ='''(0)石头(1)剪刀(2)布 请选择:'''
        ind = int(input(put))
        poeple = all_choioces[ind]
        print('你出的:%s,计算机出的是:%s' % (poeple, compute))
        if poeple == compute:
            print('\033[32;1m平局\033[0m')
        elif [poeple, compute] in win_list:
            print('\033[31;1m你赢了\033[0m')
            poeple_add += 1
            if poeple_add == 2:
                poeple_on = False
                print('\033[32;1m游戏结束\033[0m')
        else:
            print('\033[31;1m计算机赢了\033[0m')
            compute_add += 1
            if compute_add == 2:
                poeple_on = False
                print('\033[32;1m游戏结束\033[0m')

    第二种简单的格式

    import random
    all_choioces = ['石头', '剪刀', '布']
    win_list = [['石头', '剪刀'], ['剪刀', '布'], ['布', '石头']]
    poeple_add = 0
    compute_add = 0
    while poeple_add < 2 and compute_add < 2 :
        compute = random.choice(all_choioces)
        put ='''(0)石头(1)剪刀(2)布 请选择:'''
        ind = int(input(put))
        poeple = all_choioces[ind]
        print('你出的:%s,计算机出的是:%s' % (poeple, compute))
        if poeple == compute:
            print('\033[32;1m平局\033[0m')
        elif [poeple, compute] in win_list:
            print('\033[31;1m你赢了\033[0m')
            poeple_add += 1
        else:
            print('\033[31;1m计算机赢了\033[0m')
            compute_add += 1

     

    展开全文
  • 1 # -*- coding:utf-8 -*- 2 import random 3 4 # best of three 5 def finger_guess(): 6 rule = {1:'rock', 2:'paper', 3:'scissor'} ... 7 win_way = [['rock', 'scissor'], ['paper', 'rock...
     1 # -*- coding:utf-8 -*-
     2 import random
     3 
     4 # best of three
     5 def finger_guess():
     6     rule = {1:'rock', 2:'paper', 3:'scissor'}
     7     win_way = [['rock', 'scissor'], ['paper', 'rock'], ['scissor', 'paper']]
     8     num_list = [1, 2, 3]
     9     count = 0
    10     person_score = 0
    11     computer_score = 0
    12     while count < 3:
    13         person = raw_input('please input your choice:\n1.rock\n2.paper\n3.scissor\n')
    14         computer = random.choice([1, 2, 3])
    15         try:
    16             person = int(person)
    17             if person in num_list:
    18                 print 'your: %s, computer: %s' %(rule[person], rule[computer])
    19                 if rule[person] == rule[computer]:
    20                     print 'Same! One more try!'
    21                     continue
    22                 for item in win_way:
    23                     if rule[person] == item[0] and rule[computer] == item[1]:
    24                         print 'Win once! Come on!'
    25                         person_score += 1
    26                     if rule[person] == item[1] and rule[computer] == item[0]:
    27                         print 'Lose once! Never mind!'
    28                         computer_score += 1
    29             else:
    30                 print 'Are you kidding me! Please respect the Holy Game!'
    31                 continue
    32             count += 1
    33             if computer_score == 2 or person_score == 2:
    34                 break
    35         except ValueError:
    36             print 'Please input num in [1, 2, 3], Stupid!'
    37     return person_score, computer_score
    38 
    39 print 'This is a game called finger_guess, you have three choices.\nWanna beat the AI, let us try!'
    40 person_score, computer_score = finger_guess()
    41 print 'final score:\nyour:%d computer:%d' %(person_score, computer_score)
    42 if person_score > computer_score:
    43     print 'You get it'
    44 else:
    45     print 'You are so pussy!!'

     

    转载于:https://www.cnblogs.com/laresh/p/6526422.html

    展开全文
  • python实现 三局两胜石头剪刀布

    千次阅读 2018-08-15 19:26:15
    import random ...win_list = [['剪刀', ''], ['', '石头'], ['石头', '剪刀']] prompt = '''请出拳: (0) 石头 (1) 剪刀 (2) ''' cwin = 0 pwin = 0 while cwin &lt; 2 and pwin &lt; 2: c...
    import random
    
    all_choices = ['石头', '剪刀', '布']
    win_list = [['剪刀', '布'], ['布', '石头'], ['石头', '剪刀']]
    prompt = '''请出拳:
    (0) 石头
    (1) 剪刀
    (2) 布
    '''
    cwin = 0
    pwin = 0
    
    while cwin < 2 and pwin < 2:
        computer = random.choice(all_choices)
        index = int(input(prompt))
        player = all_choices[index]
    
        print('你出了:%s,计算机出了:%s' % (player, computer))
        if player == computer:
            print('\033[32;1m平局\033[0m')
        elif [player, computer] in win_list:
            print('\033[32;1m你赢了!\033[0m')
            pwin += 1
    
        else:
            print('\033[31;1m你输了!\033[0m')
            cwin += 1
    else:
        if cwin > pwin:
            print('三局两胜!你输了!')
        else:
            print('三局两胜!你赢了!')

     

    展开全文
  • i=1 #控制回合数 n=0 #记录平的次数 ...print(“三局两胜猜拳”) while i &amp;lt;= 3: print(“请出招:”) b = input() a = random.choice([1, 2, 3]) if a == 1: print(“石头”) i...
    i=1 #控制回合数
    n=0 #记录平的次数
    n1=0 #记录赢的次数
    n2=0 #记录输的次数
    print("三局两胜猜拳")
    while i <= 3:
        print("请出招:")
        b = input()
        a = random.choice([1, 2, 3])
        if a == 1:
            print("石头")
        if a == 2:
            print("剪刀")
        if a == 3:
            print("布")
        if b == "石头":
            if a == 1:
                print("平")
                n+=1
            if a == 2:
                print("赢")
                n1+=1
            if a == 3:
                print("输")
                n2 += 1
        if b == "剪刀":
            if a == 1:
                print("输")
                n2 += 1
            if a == 2:
                print("平")
                n += 1
            if a == 3:
                print("赢")
                n1 += 1
        if b == "布":
            if a == 1:
                print("赢")
                n1 += 1
            if a == 2:
                print("输")
                n2 += 1
            if a == 3:
                print("平")
                n += 1
        i+=1
        print(" ")
        if n>=2 or (n == 1 and n1 == 1 and n2 == 1) :
            print("平,继续")       #如果打平,将继续循环,直到分出胜负
            print(" ")
            i=3
        if n1>=2 :
            print("赢")
            break
        if n2>=2 :
            print("输")
            break
    展开全文
  • 闲暇之余,做了一个关于剪刀石头布三局两胜的小程序,希望它在给大家带来快乐之中,也能让大家更加了解Python里面的简单语句。首先设置 使用者 电脑 平局 赢局数都为0 from random import randint user_win=0 ...
  • 以字符串'石头','剪刀','布'的方式计算出胜负,需把每种方法一一列举,此方法较为繁琐,因此我们用012分别代替石头剪刀布我们需要分别将用户,电脑赢的次数,平局的计数,以便于我们通过他们计算出胜负平局。...
  • 游戏三局两胜 import random 定义人胜利的列表 win_list = [[‘石头’, ‘剪刀’], [‘剪刀’, ‘’], [‘’, ‘石头’]] 人机分别出拳 all_choice = [‘石头’, ‘剪刀’, ‘’] prompt = “”"(0) 石头 (1) ...
  • 实现循环结构,要求游戏三局两胜 4.2 方案 用while循环语句让游戏执行3次,在判断输赢之前用if嵌套方式先判断用户输入的值是否合法,如果合法进行输赢判断,如果不合法重新执行循环语句,三次游戏结束后,即循环结束...
  • python猜拳游戏三局两胜

    千次阅读 2018-05-04 18:36:33
    #猜拳三局两胜 from random import randint print("游戏开始,三局两胜制!") recdict=[] x=0 y=0 for i in range(3): rand=randint(1,99) list=['石头','剪刀',''] windict={('石头','剪刀'),('剪刀',''),('...
  • python之猜拳小游戏,三局两胜

    千次阅读 2019-04-02 15:40:02
    print("这是一个猜拳游戏,三局两胜") print("剪刀(0)石头(1) (2)") win = 0 lose = 0 while win<2 and lose<2: player = int(input("请输入:剪刀(0) 石头(1) (2):")) my = random....
  • import random choicelist = ["石头","剪刀",...winlist = ["石头剪刀","剪刀布","布石头"] playCNT = 0 #回合数 q = 0 #玩家比分 w = 0 #电脑比分 while playCNT!=3: AIchoice = random.choice(['石头','剪刀','...
  • win_list = [[‘石头’, ‘剪刀’],[‘剪刀’, ‘’],[‘’, ‘石头’]] prompt = ”’ (0) 石头 (1) 剪刀 (2) 请选择0/1/2: ”’ x = 0 y = 0 i = 1 while i &amp;lt;= 3: ind = int...
  • #三局两胜(赢1平2也为胜) #定义赢一次加一分,输一次减一分,平局不加分也不减分 #如果分值大于0为赢,等于0为平,小于0为输 import random choice_lists = ['石头', '剪刀', ''] play_num = 0 #统计游戏次数...
  • 该程序可以实现游戏轮次统计,双方得分、平局次数统计和重新开始功能,不管是1局决胜负,还是三局两胜、七局三胜,都能完美解决。 /2 具体实现/ 下面给大家详细介绍一下具体步骤。 第一步:创建游戏主窗口 PyQt...
  • 于是我开始小试牛刀,用PyQt5做个可视化的“剪刀石头布”小游戏,总体效果如下:该程序可以实现游戏轮次统计,双方得分、平局次数统计和重新开始功能,不管是1局决胜负,还是三局两胜、七局三胜,都能完美解决。...

空空如也

空空如也

1 2 3
收藏数 43
精华内容 17
关键字:

python石头剪刀布三局两胜

python 订阅