0528习题 1-5

时间:2020-05-28
本文章向大家介绍0528习题 1-5,主要包括0528习题 1-5使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
'''
1.    编写程序实现:计算并输出标准输入的三个数中绝对值最小的数。
'''
#计算并输出标准输入的三个数中绝对值最小的数。
import math
num1 = int(input())
num2 = int(input())
num3 = int(input())
num_list = (num1, num2, num3)
index_min = 0    #绝对值最小的元素的下标
if math.fabs(num_list[index_min]) > math.fabs(num_list[1]):
    index_min = 1
if math.fabs(num_list[index_min]) > math.fabs(num_list[2]):
    index_min = 2

for n in num_list:
    if math.fabs(num_list[index_min]) == math.fabs(n):
        print(n, end=' ')

'''
2.    编写程序,功能是输入五分制成绩,
输出对应的百分制分数档。 不考虑非法输入的情形。
对应关系为:A: 90~100, B: 80~89, C: 70~79,D: 60~69, E: 0~59
'''
score = int(input())
if 90 <= score <= 100:
    print("A")
elif 80 <= score <= 89:
    print("B")
elif 70 <= score <= 79:
    print("C")
elif 60 <= score <= 69:
    print("D")
elif 0 <= score <= 59:
    print("E")
else:
    print("请输入正确分数")

'''
3.    编写程序,
输入年(year)、月(month),输出该年份该月的天数。
公历闰年的计算方法为:年份能被4整除且不能被100整除的为闰年;
或者,年份能被400整除的是闰年。
'''
year = int(input("请输入年份"))
month = int(input("请输入月份"))
month_lst = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if (year %4 == 0 and year % 100 !=0) and year % 400 == 0:
    month_lst[1] = 29
print(month_lst[month - 1])

'''
4.    编写程序,功能是输入一个数,输出该数的绝对值
'''
num = int(input())
print(abs(num))

'''
5.    编写“猜数游戏”程序,
功能是:
如果用户输入的数等于程序选定的数(该数设定为10),则输出“you win”,
否则如果大于选定的数,则输出“too big”,反之输出“too small”。
'''
num = 10
your_num = int(input())
if your_num == num:
    print("you win")
elif your_num > num:
    print("too big")
else:
    print("too small")

2020-05-28

原文地址:https://www.cnblogs.com/hany-postq473111315/p/12978717.html