函数练习题

这篇博客主要介绍了11个Python函数编程题目,涵盖日期计算、数字判断、字符串操作、列表处理、字典转换等方面,还涉及到了名片管理系统的实现,包括添加、删除、修改和查询名片功能。
摘要由CSDN通过智能技术生成

1. 定义一个函数,用于求2017年1月到今天的总天数,打印总天数

def is_leapyear(year):
    if year % 400 == 0:
        return True
    else:
        return False
        
def allyear_days(year):
    if is_leapyear(year):
        return 366
    else:
        return 365

def total_days(year, month, day):
    count = 0
    leap_dict = {
   1: 31, 2: 29, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
    noleap_dict = {
   1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
    for i in range(2017, year):
        s = allyear_days(i)
        count += s
    for j in range(month - 1):
        if is_leapyear(year):
            count += leap_dict[j+1]
        else:
            count += noleap_dict[j+1]
    count += (day-1print(count)

2.定义一个函数,实现判断参数传入的是否全部是数字,返回值是True或者False(不使用isdigit)

def isdigit(n):
    length = len(n)
    count = 0
    l1 = ['0','1',
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值