前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >01月26日【Python3 基础知识】

01月26日【Python3 基础知识】

作者头像
py3study
发布2020-01-03 15:30:12
2200
发布2020-01-03 15:30:12
举报
文章被收录于专栏:python3python3python3

01月26日【Python3 基础知识】

5.1 九宫格 5.2 函数入门 5.3 判断某天为某年的第几天

5.1 九宫格

import random
x = 0
l = [1,2,3,4,5,6,7,8,9]
print("*************")
while len(l) != 0:
    n = int(random.random() * 100 % len(l))
#print(x)
#print(n)
    d = l.pop(n)
    print("|_{0}_".format(d),end="")
    x += 1
    if x == 3:
        print("|")
        x = 0
print("*************")

5.2 函数入门

# 函数
def a(args):
    pass
##################
def add(args):
    total = 0
    for i in args:
        total += i
    return total
def main():
    number = list()
    s = input("请输入(a + b + c + d + ...):")
    for num in s.split("+"):
        number.append(int(num.strip()))
    print(add(number))
if __name__ == '__main__':
    main()

5.3 判断某天为某年的第几天

a = {"1":31, "2":28, "3":31, "4":30, "5":31, "6":30, "7":31, "8":31,
     "9":30, "10":31, "11":30, "12":31}
b = {"1":31, "2":29, "3":31, "4":30, "5":31, "6":30, "7":31, "8":31,
     "9":30, "10":31, "11":30, "12":31}
days = 0
date = input("输入日期(1970-1-1):")
year, month, day = date.split("-")
if int(day) > 31:
    print("输入错误!")
elif int(month) > 12:
    print("输入错误!")
elif ((int(year) % 4 == 0) and (int(year) % 100 != 0)) or ((int(year) % 100 == 0) and (int(year) % 400 == 0)):
    if b[month] < int(day):
        print("输入错误!")
    else:
        for k, y in b.items():
            if int(k) < int(month):
                days += int(y)
        print("{0}是今年的第{1}天!".format(date, days + int(day)))
else:
    if a[month] < int(day):
        print("输入错误!")
    else:
        for k, y in a.items():
            if int(k) < int(month):
                days += int(y)
        print("{0}是今年的第{1}天!".format(date, days + int(day)))
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 01月26日【Python3 基础知识】
    • 5.1 九宫格
      • 5.2 函数入门
        • 5.3 判断某天为某年的第几天
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档