python学习日记(二)

题库2

P1422

print("%.3f"%c)强制输出c为3位小数

P1085

本题是一个for循环使用,有一种顺序排序法的感觉。

t = 0
a = 0
for i in range(1,8):
    x,y = map(int,input().split())
    h_index = x + y
    if h_index > t:
        t = h_index
        a = i
if t > 8:
    print(i)
else:
    print(0)

output:
在这里插入图片描述在这里插入图片描述

P1089***

这道题debug了很久

错误代码

own = 0
reposit = 0
c = 1
d = []
for i in range(1,13):
    budget = int(input())
    a = 300 + own - budget
    b = a // 100
    if a < 0:
        c = 0
        d.append(-i)
    else:
        if b >= 1:
            reposit = reposit + b
            own = a - b*100
        else:
            own = a
if c == 1:
    print(int(reposit * 1.2 * 100 + own))
else:
    print(int(d[0]))

正确代码

own = 0
reposit = 0
c = 1
d = []
for i in range(1,13):
    budget = int(input())
    a = 300 + own - budget
    b = a // 100
    if a < 0:
        c = 0
        d.append(-i)
    else:
        if b >= 1:
            reposit = reposit + b
            own = a - b*100
        else:
            own = a
if c == 1:
    print(int(reposit * 120 + own))
else:
    print(int(d[0]))

出现错误的测试点:
input
288
225
151
95
279
203
65
300
266
232
199
60
output_correct = 1477
output_error_code = 1476

出现错误的原因:
错误代码最后输出是deposit * 1.2 * 100 + own ; 这样算出来的话是1476.999998,输出的时候自己用的int(),而int()是向下取整。因此错误。
关键在于,为什么会出来1476.99998 这个数???

P1909

简单
循环套循环

money = 1e10
req = int(input())
for i in range(3):
    pen, pr = map(int,input().split())
    package = req // pen
    a = req % pen
    if a == 0:
        b = package * pr
        if money > b:
            money = b
    else:
        b = (package+1) * pr
        if money > b:
            money = b
print(money)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值