继续做题~经过python3的测试

原题链接:http://www.runoob.com/python/python-exercise-example4.html

题目:输入某年某月某日,判断这一天是这一年的第几天?

我的代码:

year=int(input("please input the year:"))
month=int(input("please input the month:"))
day=int(input("please input the day:"))
Month=[31,28,31,30,31,30,31,31,30,31,30,31] #用一个list存储每个月的天数
i=0
total=day
while i<month-1:               #用循环加上之前每个月天数
total +=Month[i]
i+=1
if year%400==0 or (year%4==0 and year%400 != 0): #判断闰年,跟闰年的定义有关
if month>2:
total+=1
print("It is the %dth day." %total)

思考:输入年月日只能分开吗?不能以列表形式输入吗?

可以先定义一个list,用for循环加上append输入:

date = []
print("please input year month and day:")
for i in range(3):
date.append(eval(input()))      #eval也可以换为int

这样要输入回车x3次。

也可以用split函数加上list函数一次输入:

date=list(input("please input year,month,day:").split(","))

但是这样在date列表中的元素都是str,之后使用要转为int。

python3练习100题——004的更多相关文章

  1. python3练习100题——003

    今天继续-答案都会通过python3测试- 原题链接:http://www.runoob.com/python/python-exercise-example3.html 题目:一个整数,它加上100 ...

  2. python3练习100题——002

    因为特殊原因,昨天没有做题.今天继续- 原题链接:http://www.runoob.com/python/python-exercise-example2.html 题目: 企业发放的奖金根据利润提 ...

  3. python3练习100题——036

    原题链接:http://www.runoob.com/python/python-exercise-example36.html 题目:求100之内的素数. 之前有类似的题,所以这次遇到觉得很容易了, ...

  4. python3练习100题——035

    原题链接:http://www.runoob.com/python/python-exercise-example34.html 题目:文本颜色设置. 学习了一下python3 的文本颜色设置. 其实 ...

  5. python3练习100题——020

    原题链接:http://www.runoob.com/python/python-exercise-example20.html 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半:再落下 ...

  6. python3练习100题——013

    熟悉的水仙花数来了,,,... 原题链接:http://www.runoob.com/python/python-exercise-example13.html 题目:打印出所有的"水仙花数 ...

  7. python3练习100题——056

    题目:画图,学用circle画圆形. 可以用turtle.circle画图. import turtle turtle.setup(0.6,0.6) turtle.pensize(3) turtle. ...

  8. python3练习100题——050

    题目:输出一个随机数. 程序分析:使用 random 模块. import random print( random.randint(1,10) ) # 产生 1 到 10 的一个整数型随机数 pri ...

  9. python3练习100题——045

    题目:统计 1 到 100 之和. sum(range(1,101)) 题目太容易了,我都不想用迭代浪费时间. 觉得这100道题难度设计越来越不合理.

随机推荐

  1. debian 和ubuntu 安装ifconfig 命令

    # apt update # apt install net-tools

  2. NodeJS 介绍安装

    1.NodeJS简介 Node.js是基于Chrome JavaScript运行时建立的一个平台,实际上它是对Google Chrome V8引擎进行了封装,它主要用于创建快速的.可扩展的网络应用.N ...

  3. Unable to update index for nexus-publish | http://ip:port/repository/maven-public/

    问题描述:Unable to update index for nexus-publish | http://ip:port/repository/maven-public/ 解决方案:进入工作空间. ...

  4. 1282 - Leading and Trailing 求n^k的前三位和后三位。

    1282 - Leading and Trailing You are given two integers: n and k, your task is to find the most signi ...

  5. package包

    为什么需要package? 为了解决类之间的重名问题.为了方便管理类,合适的类放在合适的包. 怎么用package? 通常是类的第一句非注释性语句. 包名,域名倒着写,加上模块名,并与内部管理类. 命 ...

  6. Codeforces 1301B Motarack's Birthday(二分)

    题目链接:http://codeforces.com/problemset/problem/1301/B 思路: (1)都是-1的情况 (2)只有一个除-1之外的数 (3)至少有两个除-1之外的不同的 ...

  7. #《H.264和MPEG-4视频压缩》# 一. 色彩空间

    多数的数字视频应用需要播放彩色的视频信号,所以需要捕获和重现颜色信息.一幅黑白图像的每一个采样点只需要一个像素表示明暗或亮度,而在彩色图像中至少需要3个像素来表示每个像素的色彩.表示亮度和色彩的不同方 ...

  8. 树莓派点亮LED灯需要几行代码?3行。小孩子都能学会

    目录 点亮LED灯 硬件连接 代码 闪烁的LED灯 呼吸灯 其他 点亮LED灯 硬件连接 找一个LED灯,连接如上图,注意长短引脚,经过这些年的狂轰乱炸,大家对于这个应该不漠视,毕竟Arduino都进 ...

  9. 折腾vue--使用vscode创建vue项目(二)

    1.安装webpack npm install -g webpack 2.安装sass npm install --save-dev sass-loader npm install --save-de ...

  10. Q&A in 2018 - Q2

    How to zip a file for Windows? 压缩一个文件: makecab c:/file_name.txt c:/file_name.zip 解压一个文件: expand c:/f ...