乒乓球(python3做法)

这里写图片描述
这里写图片描述

#encoding:utf-8

lst = []
lst1 = []
s = 0
while True:
    lst1 = list(input())
    for i in lst1:
        if i != 'E':
            lst.append(i)
        else:
            s = 1
            break
    if s == 1:
        break

a, b = 0, 0
for i in lst:
    if i == 'W':
        a = a + 1
    if i == 'L':
        b = b + 1
    if (a >= 11 or b >= 11) and (a - b >= 2 or b - a >= 2):
        print("%d:%d"%(a, b))
        a, b, s1 = 0, 0, 1
        continue

if a > 0 or b > 0:
    print("%d:%d"%(a, b))
if a == 0 and b == 0:
    print("0:0")
print()

a, b = 0, 0
for i in lst:
    if i == 'W':
        a = a + 1
    if i == 'L':
        b = b + 1
    if (a >= 21 or b >= 21) and (a - b >= 2 or b - a >= 2):
        print("%d:%d"%(a, b))
        a, b= 0, 0
        continue

if a > 0 or b > 0:
    print("%d:%d"%(a, b))
if a == 0 and b == 0:
    print("0:0")

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
乒乓球比赛可以使用Python编写程序来生成比赛名单。在程序中,可以使用列表来存储参赛选手的姓名,使用循环和条件语句来筛选符合要求的比赛名单。例如,可以使用以下代码来生成符合条件的比赛名单: ``` players = ['a', 'b', 'c', 'x', 'y', 'z'] for a in players: for b in players: for c in players: if a != b and a != c and b != c and a != 'x' and c != 'x' and c != 'z': print('a对战%s\nb对战%s\nc对战%s' % (a, b, c)) ``` 这段代码会输出符合条件的比赛名单,其中a不和x比,c不和x、z比。输出结果如下: ``` a对战y b对战z c对战x a对战z b对战y c对战x ``` 除了生成比赛名单,还可以使用Python编写程序来模拟乒乓球比赛的得分情况。根据乒乓球规则,一局比赛中先得11分为胜,当双方得分相同时,需要继续比赛直到有一方先得2分为止。一场比赛采用三局两胜制,当每人各赢一局时,最后一局为决胜局。可以使用以下代码来模拟一场乒乓球比赛: ``` import random def play_game(): score_a = 0 score_b = 0 while True: if score_a >= 11 and score_a - score_b >= 2: return 'a' elif score_b >= 11 and score_b - score_a >= 2: return 'b' else: winner = random.choice(['a', 'b']) if winner == 'a': score_a += 1 else: score_b += 1 def play_match(): score_a = 0 score_b = 0 while True: winner = play_game() if winner == 'a': score_a += 1 else: score_b += 1 if score_a == 2 or score_b == 2: break if score_a > score_b: return 'a' else: return 'b' winner = play_match() print('比赛胜者是:%s' % winner) ``` 这段代码会模拟一场乒乓球比赛,输出比赛胜者的姓名。在程序中,使用了随机数来模拟比赛过程,当一方得分达到11分并且领先对手2分时,该方获胜。如果双方得分相同,需要继续比赛直到有一方先得2分为止。一场比赛采用三局两胜制,当某一方获得两局胜利时,比赛结束。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值