python实现的话,6,8,11三道题没有办法通过吧?求确认!

P2433 【深基1-2】小学数学 N 合一

xixi_coding @ 2022-04-15 22:48:42

import math

t = int(input())

if t == 1:
    print('I love Luogu!')
elif t == 2:
    print(2 + 4, 10 - 2 - 4)
elif t == 3:
    a = 14 // 4
    print(a)
    print(a * 4)
    print(14 % 4)

elif t == 4:
    print(round(500 / 3, 3))

elif t == 5:
    print((260 + 220)//(12+20))

elif t == 6:
    def cout():
        print(math.sqrt(36 + 81))
    cout()
elif t == 7:
    money = 100
    money = money + 10
    print(money)
    money = money - 20
    print(money)
    print(0)

elif t == 8:
    r = 5
    a = 3.141593
    print(a * r*2)
    print(a * r**2)
    print(4/3 * a * r**3)

elif t == 9:
    x = 1
    for i in range(3):
        x = (x + 1) * 2
    print(x)

elif t == 10:
    y = (8 * 30 - 10 * 6)/(30 - 6)
    x = 8 * 30 - 30 * y
    z = int((x + 10 * y) / 10)
    print(z)

elif t == 11:
    print(100/(8-5))

elif t == 12:
    print(ord('M') - ord('A') + 1)
    print(chr(ord('A') + 18 - 1))

elif t == 13:
    pi = 3.141593
    print(int((4/3 * pi * 4 ** 3 + 4/3 * pi * 10 ** 3)**(1/3)))

elif t == 14:
    price = 110
    n = 10
    a = 0
    b = 0
    while price > 0:
        price -= 1
        n += 1
        if n * price == 3500:
            a = price
            b = n
    print(a)

by Missa @ 2022-04-15 22:52:37

这里的 cout 指的是 c++ 中的 cout,你的 python 估计被卡小数位数了。


by Terrible @ 2022-04-15 22:56:51

@fqx_218

cout默认6位有效数字,Python的C格式化输出:print("%.6g"%f)


by xixi_coding @ 2022-04-15 23:14:57

@Terrible 我去试一下


by 176lhp @ 2022-06-16 10:52:34

@Terrible 保留6位有效数字和保留6位小数一样吗?


by Terrible @ 2022-06-16 12:26:50

@176lhp 不一样,保留6位有效数字是从第一个非零数字开始算6位,保留6位小数是从小数点后算6位。

比如 3.1415926 四舍五入保留6位有效数字是 3.14159,保留6位小数是 3.141593


by BG5CNR @ 2023-05-01 18:18:50

@fqx_218 请问,14题用枚举的话,怎么取到小的值?用枚举是两个值都会输出的。


|