团体程序设计天梯赛-练习集2(10分题)

API练习题的链接如下 :

https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7


拖了好久,在更新几道,正在自己看网站学习python中,所以,目前打的代码都是根据自己学的内容写的,可能不是最优代码。欢迎在评论区交流。
 

目录

L1-040 最佳情侣身高差 

L1-041 寻找250

L1-007 念数字 

L1-068 调和平均 

L1-055 谁是赢家

L1-084 拯救外星人 

L1-099 帮助色盲


L1-040 最佳情侣身高差 

import math
# 定义函数
def is_shen_gao(sex,h):
    if sex == 'F':
        perfect = h * 1.09
        print("%.2f"%(perfect))
    elif sex == 'M':
        perfect = h/1.09 
        print("%.2f"%(perfect))
# 调用函数
N = int(input())
if N <= 10:
    numbers = []
    for i in range(N):
        sex,h = input().split()
        h = float(h)
        numbers.append((sex,h))
    if  1.0 < h <= 3.0:
        for y in numbers:
            is_shen_gao(y[0], y[1])
    else:
        print("身高不合理")
else:
    print("N大于10")

L1-041 寻找250

N = input()
numbers = list(map(int, N.split()))
position = []
for p,i in enumerate(numbers):
    if i == 250:
        position = p+1
        break
print(f"{position}") 

L1-007 念数字 

N = input().split()
pin_yin = {
    '0': 'ling',
    '1': 'yi',
    '2': 'er',
    '3': 'san',
    '4': 'si',
    '5': 'wu',
    '6': 'liu',
    '7': 'qi',
    '8': 'ba',
    '9': 'jiu',
}
result = []
B = True
for num in N:
    if num.startswith('-'):
        result.append('fu')
        num = num[1:] 
    for d in num:
        result.append(pin_yin[d])
print(" ".join(result))

L1-068 调和平均 

# 定义函数,求调和平均
def tiao_he(numbers):
    sum = 0
    for x in numbers:
        for y in x:
            sum += (1/y)/N
    result = float(1/sum)
    return result
N = int(input())
if N <=1000:
    numbers = []
    num = list(map(float,input().split()))
    numbers.append(num)
# 调用函数
    r = tiao_he(numbers)
    print("%.2f"%(r))
else:
    print("N大于1000")

L1-055 谁是赢家

# 定义函数,判断赢家
def prime_winner(Pa,Pb,a,b):
    if Pa > Pb and a > 0:
        P1 = Pa
        if a > b:
            P2 = a
            print(f"The winner is a: {P1} + {P2}")
        else:
            P2 = a
            print(f"The winner is a: {P1} + {P2}")
    else:
        P1 = Pb
        if a > b:
            P2 = b
            print(f"The winner is b: {P1} + {P2}")
        else:
            P2 = b
            print(f"The winner is b: {P1} + {P2}")

Pa,Pb = map(int,input().split())
if Pa <= 1000 and Pb <= 1000:
    N = input().split()
    numbers = []
    for i in (N):
        numbers.append((i))
    count1 = 0 # 记录给b选手投票的评委票数
    count2 = 0 # 记录给a选手投票的评委票数
    for x in numbers:# 通过循环去进行票数计算
        if x == '1':
            count1 += 1
        else:
            count2 += 1
    a = count2
    b = count1
    # 调用函数
    prime_winner(Pa,Pb,a,b)

L1-084 拯救外星人 

A,B = map(int,input().split())
N = A + B
s=1
for i in range(1,N):
    i = i+1
    s = i * s
print(s)

L1-099 帮助色盲

# 定义函数,判断执行动作
def prime_zhixing(A,B):
    if A == '0'and B == '0':
        print("biii\nstop")
    elif A == '0'and B == '1':
        print("-\nstop")
    elif A == '1'and B == '0':
        print("dudu\nmove")
    elif A == '1'and B == '1':
        print("-\nmove")
    elif A == '2'and B == '0':
        print("-\nstop")
    elif A == '2'and B == '1':
        print("-\nstop")
A, B = map(str,input().split())
prime_zhixing(A,B)

在这里,需要注意的就是灯是黄灯的时候,不管有没有同向的人,都需要停下来。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值