0分求助(Python)

P1422 小玉家的电费

HAPPY804 @ 2024-02-02 11:04:32

a=int(input())

if a>150:

if a>400:

    a=(a-400)*0.5663

    a=a+150*0.4463

    a=a+(400-150)*0.4663

else:

    a=(a-150)*0.4663

    a=a+150*0.4463

else:

a=a*0.4463

print(a)


by KDKdjkjNjJdN @ 2024-02-15 22:09:16

(话说你样例都不正确你怎么敢提交的)
逻辑是对的,但请仔细审一审题,人家让你保留到小数点后1位……
这么四舍五入就可以了:


print(round(a, 1)) #保留到小数点后1位 
想知道具体使用round()函数的办法可以点这里[这里](https://blog.csdn.net/qq_34035425/article/details/123237006?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170800564516800184187381%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170800564516800184187381&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-3-123237006-null-null.142^v99^control&utm_term=python%E4%B8%AD%E5%9B%9B%E8%88%8D%E4%BA%94%E5%85%A5%E7%9A%84%E5%87%BD%E6%95%B0&spm=1018.2226.3001.4187)

by KDKdjkjNjJdN @ 2024-02-15 22:11:58

@ckx0804 把我刚才发的代码最后一行给删了就行,洛谷好像出bug了
对了,想知道具体使用round()函数的办法可以点这里


by HAPPY804 @ 2024-02-17 18:24:13

@TPJ_XiaoJing_python 谢了!AC了


|