牛客网刷题-(6)

简介: 牛客网刷题-(6)

(1)闰年判断

伪代码:

year = (int(input()))
if (year % 100 == 0 and year % 400 == 0) or (year % 100 != 0 and year % 4 == 0):
    print("year是闰年")
else:
    print("year不是闰年")

tip2:👉🔗http://t.csdnimg.cn/G1ZQ8

(2)判断大小

#if- else 法:
a,b = map(int,input().split())
if a > b:
    max_value = a
else:
    max_value = b
print(max_value)
#三元换算法:  等价于 原始是a 如果 a > b 就是b
max_value = a if a > b else b
print(max_value)

Match 语句:

status = int(input())
match status:
    case 400:
        print("Bad request")
    case 404:
        print("Not found")
    case 418 | 420 | 422 | 400: #| 表示或
        print("I'm a teapot")
    case _: #_ 表示方法
        print("Something's wrong with the internet")

1.字符串中想表示%时,需要写成 %%.

2.Python 中交换两个变量, 可以用: a,b = b,a.

(3)零食

写法1:

#零食
x,y = map(int,input().split())
if x == 1:
    print("Total: R$ %.2f"%(y * 4))
elif x == 2:
    print("Total: R$ %.2f"%(y * 4.5))
elif x == 3:
    print("Total: R$ %.2f"%(y * 5))
elif x == 4:
    print("Total: R$ %.2f"%(y * 2))
elif x == 5:
    print("Total: R$ %.2f"%(y * 1.5))

写法2:

#写法2:
x,y = map (int,input().split())
if x == 1:
    p = 4
elif x == 2:
    p = 4.5
elif x == 3:
    p = 5
elif x == 4:
    p = 2
else:
    p = 1.5
print("Total : R$ %.2f" % (p * y))

(4)加薪

方法1:

#加薪
s = float(input())
if 400 >= s > 0 :
    print("Novo salario: %.2f"%(s * (1+0.15)))
    print("Reajuste ganho: %.2f"%(s * 0.15))
    print("Em percentual: %d %%"%(15))
elif 800 >= s >= 400.01:
    print("Novo salario: %.2f"%(s * (1+0.12)))
    print("Reajuste ganho: %.2f"%(s * 0.12))
    print("Em percentual: %d %%"%(12))
elif 1200 >= s >= 800.01:
    print("Novo salario: %.2f"%(s * (1+0.1)))
    print("Reajuste ganho: %.2f"%(s * 0.1))
    print("Em percentual: %d %%"%(10))
elif 2000 >= s >= 1200.01:
    print("Novo salario: %.2f"%(s * (1+0.07)))
    print("Reajuste ganho: %.2f"%(s * 0.07))
    print("Em percentual: %d %%"%(7))
else:
    print("Novo salario: %.2f"%(s * (1+0.04)))
    print("Reajuste ganho: %.2f"%(s * 0.04))
    print("Em percentual: %d %%"%(4))

方法2:

x = float(input())
if x <= 400:
    y = 15
elif x <= 800:
    y = 12
elif x <= 1200:
    y = 10
elif x <= 2000:
    y = 7
else:
    y = 4
print("Novo salario:x %.2f" % (x * (1 + y / 100)))
print("Reajuste ganho: %.2f" % (x * (y / 100)))
print("Em percentual: %d %" % y)

目录
相关文章
|
6月前
牛客网刷题总结4-22
牛客网刷题总结4-22
29 0
|
11月前
牛客网刷题-(7)
牛客网刷题-(7)
37 1
|
11月前
牛客网刷题-(10)
牛客网刷题-(10)
39 0
|
11月前
牛客网刷题-(5)
牛客网刷题-(5)
43 0
|
11月前
牛客网刷题-(11)
牛客网刷题-(11)
37 0
|
11月前
牛客网刷题-(3)
牛客网刷题-(3)
38 0
|
11月前
牛客网刷题-(9)
牛客网刷题-(9)
47 0
|
11月前
牛客网刷题-(4)
牛客网刷题-(4)
34 0
|
11月前
|
Python
牛客网刷题-(1)
牛客网刷题-(1)
52 0
|
11月前
牛客网刷题-(8)
牛客网刷题-(8)
41 0