根据月日计算天数
""" 练习2: 根据月日,计算是这一年的第几天. 公式:前几个月总天数 + 当月天数 例如:5月10日 计算:31 29 31 30 + 10 """ list_months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] month = int(input("请输入月份:")) day = int(input("请输入天数")) print("%s月%.2日在一年中是第%s天" % (month, day, sum(list_months[:month - 1]) + day))
根据输入打印原色
color = input("请输入颜色:").upper() # 转换为大写 dict_color = { "R":"红色", "G":"绿色", "B":"蓝色", "A":"透明度" } if color not in dict_color: continue print(dict_color[color])
列表累减
list_number = [5, 1, 4, 6, 7, 4, 6, 8, 5] difference = list_number[0] for i in range(1,len(list_number)): difference -= list_number print(difference)
最大值最小值
list_number = [5, 1, 4, 6, 7, 4, 6, 8, 5] max_number = list_number[0] for item in list_number: if max_number >= item: continue max_number = item min_number = list_number[0] for item in list_number: if min_number <= item: continue min_number = item print("列表大最大值是%s最小值是%S" % (max_number,min_number))
标签:python,31,30,list,number,color,dict,字典 From: https://www.cnblogs.com/xmgcool/p/16960139.html