PAT甲级1011 World Cup Betting——python

一共有三个输入,我们还要把他们转化为小数,注意他输入的是一个字符串,我们需要把他们转化成小数,注意分割位置,我们需要寻找空格,分割的代码如下:

x = '1.76 1.6 1.43'
x = list(x)
x.append(' ')
print(x)
n = 0
m = []
for i in range(len(x)):
    if x[i] == ' ':

        m.append(''.join(x[n:i]))
        n = i
print(m)
for j in m:
    print(float(j))
['1', '.', '7', '6', ' ', '1', '.', '6', ' ', '1', '.', '4', '3', ' ']
['1.76', ' 1.6', ' 1.43']
1.76
1.6
1.43

完成代码

a = ['W', 'T', 'L']
m = []
for i in range(3):
    x = list(input())
    x.append(' ')
    n = 0
    b = []
    for i in range(len(x)):
        if x[i] == ' ':
            b.append(''.join(x[n:i]))
            n = i
    for i in range(len(b)):
        b[i] = float(b[i])
    m.append(b)
res = []
Max = 1
for i in range(3):
    s = max(m[i])
    Max *= s
    res.append(a[m[i].index(s)])
print(' '.join(res),'%.2f'%((Max*0.65-1)*2))

PAT甲级1011 World Cup Betting——python

上一篇:云计算(6)_CPU虚拟化


下一篇:事件和概率