洛谷题单-入门2-分支结构-python-上

本题涉及浮点且题目没有要求输出格式的内容都需要依据C++的输出样式(超级大坑)

from math import sqrt

number = input()

result1_str = "I love Luogu!" 
if number == "1":
    print(result1_str)

result2_1 = 6
result2_2 = 4
if number == "2":
    print(result2_1, result2_2)

result3_1 = 3
result3_2 = 12
result3_3 = 2
if number == "3":
    print(result3_1)
    print(result3_2)
    print(result3_3)

result4_1 = 500 / 3
if number == "4":
    print("{:.3f}".format(result4_1))


result5_1 = 480 // 32
if number == "5":
    print("{:}".format(result5_1))

result6_1 = sqrt(6*6 + 9*9)
if number == "6":
    print("{:.4f}".format(result6_1))

result7_1 = 110
result7_2 = 90
result7_3 = 0
if number == "7":
    print("{:}".format(result7_1))
    print("{:}".format(result7_2))
    print("{:}".format(result7_3))

number_r = 5
number_pi = 3.141593
result8_1 = number_r * 2 * number_pi
result8_2 = pow(number_r, 2) * number_pi
result8_3 = (4 / 3) * number_pi * pow(number_r, 3)
if number == "8":
    print("{:.4f}".format(result8_1))
    print("{:.4f}".format(result8_2))
    print("{:.3f}".format(result8_3))

result9_1 = 22
if number == "9":
    print("{:}".format(result9_1))

result10_1 = 9
if number == "10":
    print("{:}".format(result10_1))

result11_1 = 100 / 3
if number == "11":
    print("{:.4f}".format(result11_1))

result12_1 = 13
result12_2 = 'R'
if number == "12":
    print("{:}".format(result12_1))
    print("{:}".format(result12_2))

result13_1 = 16
if number == "13":
    print("{:}".format(result13_1))

result14_1 = 50
if number == "14":
    print("{:}".format(result14_1))


需注意t为0的情况


m, t, s = map(int, input().split())
test = True
if t == 0 and test:
    print(0)
    test = False
if m * t <= s and test:
    print(0)
    test = False
if test:
    result = m - s // t if s % t == 0 else m - s // t - 1
    print(result)

后两个人的判断可以按前两个的判断结果进行得出

target = int(input())

is_1 = True
is_2 = True

if target % 2 != 0:
    is_1 = False

if target > 12 or target <= 4:
    is_2 = False

a_think = 1 if is_1 and is_2 else 0
b_think = 1 if is_1 or is_2 else 0
c_think = 1 if b_think and not a_think else 0
d_think = 1 if not b_think else 0

print(a_think, b_think, c_think, d_think)

你知道的,这就是闰年

target = int(input())

result = 1 if target % 100 == 0 and target % 400 == 0 or target % 4 == 0 and target % 100 != 0 else 0

print(result)

字符串拼接

target = int(input())
str1 = "Today, I ate "
str_target = str(target)
str2 = " apple."
str2_n = " apples."
if target == 0:
    print(str1 + str_target + str2)
elif target == 1:
    print(str1 + str_target + str2)
else:
    print(str1 + str_target + str2_n)

解方程后的判断

target = int(input())

if target < 6:
    print("Local")
else:
    print("Luogu")

BMI

m_kg, h_m = map(float, input().split())
m_kg = int(m_kg)

BMI = m_kg / h_m ** 2

if BMI < 18.5:
    print("Underweight")
elif BMI < 24:
    print("Normal")
else:
    print("{:.4f}".format(BMI))
    print("Overweight")

这个自带方法就是了,总不能手写排序算法吧

list_number = list(map(int,input().split()))
list_number.sort()

print(list_number[0], list_number[1], list_number[2])

先看是不是2月,2月才关心是不是闰年

year, month = map(int, input().split())

year_bool = True if year % 100 == 0 and year % 400 == 0 or year % 4 == 0 and year % 100 != 0 else False


if month == 2:
    if year_bool:
        print(29)
    else:
        print(28)
elif month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
    print(31)
else:
    print(30)

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值