练习1 2019-3-19
# 写一个函数实现99乘法表 def x99(x):
if x >=1 and x <=9:
line = 1
while line <= x:
start=1
while start <= line:
print('{0}*{1}={2}'.format(start,line,start*line),end=' ')
start+=1
print()
line+=1
else:
print('参数在1-9的正整数范围内!')
# 调用函数
x99(9)

练习2 2019-3-19
# 1到4能组成多少个互不相同且不重复数字的三位数?分别是?

for x in range(1,5):
for y in range(1,5):
for z in range(1,5):
if x != y and y != z and x != z:
print(x,y,z)
练习3 2019-3-19
# 计算两个列表对应相加的和,输出一个新的列表
a = [1,2,3]
b = [4,5,6]
c = []
for i in range(len(a)):
c.append(a[i]+b[i])
print(c)

 练习4 2019-3-19

# 输出一个三角形
def sjx(x):
for i in range(1,x):
print("*"*i)
sjx(4)
print('-'*50) #输出一个空心正方形
def zfx1(x):
print("*"*x)
for i in range(x-2):
print("*"+" "*(x-2)+"*")
print('*'*x)
zfx1(4)
print('-'*50) #输出一个实心正方形
def zfx2(x):
for i in range(x):
print("*"*x)
zfx2(4)
print("-"*50)
练习5 2019-3-19
# 1、一个不超过5位数的正整数,判断位数,且输出个十百千万位上的数
num = int(input("不超过5位数的正整数: "))
n = str(num)
# 按转字符串方式去获取
if len(n) > 5:
print("请输入一个不超过5位数的正整数!")
else:
for i in n[::-1]:
print(i)
print('-'*50)
# 按数字去计算获取
# for i in range(len(n)):
# print(num%10)
# num = num//10
# 2、输入一个数。计算出这个数以内的整数之和
def sum(x):
s1 = 0
for i in range(x+1):
s += i
print(s)
sum(5)
# 3、求可用被17整除的所有三位数
n = []
for i in range(99,1000):
if i % 17==0:
n.append(i)
print(n)

练习6 2019-3-19

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2019/3/19 17:18
# @Author : wangdecheng
# @Software: PyCharm import time,datetime # 输入年月日,判断这一天是这一年中的第几天?
# 方法1
# y = int(input('year:\n'))
# m = int(input('month:\n'))
# d = int(input('day:\n')) # targetDay = datetime.date(y, m, d)
# dayCount = targetDay - datetime.date(targetDay.year - 1, 12, 31)
# print('%s是%s年的第%s天。' % (targetDay, y, dayCount.days)) # 78天 # 方法2
a=[[31,28,31,30,31,30,31,31,30,31,30,31],
[31,29,31,30,31,30,31,31,30,31,30,31]] #a[0]普通年的月天数,a[1]闰年的月天数
year=int(input("年:"))
month = int(input("月:"))
day = int(input("日:"))
sum=0
if (year%4==0 and year%100!=0)or year%400==0:
for i in range(1,month):
sum=sum+a[1][i]
else:
for i in range(1,month):
sum=sum+a[0][i]
sum=sum+day
print("{}年{}月{}日是这一年的第{}天".format(year,month,day,sum))

 

Python每日练习汇总的更多相关文章

  1. Python每日一练(1):计算文件夹内各个文章中出现次数最多的单词

    #coding:utf-8 import os,re path = 'test' files = os.listdir(path) def count_word(words): dic = {} ma ...

  2. python每日一函数 - divmod数字处理函数

    python每日一函数 - divmod数字处理函数 divmod(a,b)函数 中文说明: divmod(a,b)方法返回的是a//b(除法取整)以及a对b的余数 返回结果类型为tuple 参数: ...

  3. Python IDLE快捷键汇总

    Python IDLE快捷键汇总 在Options→configure IDLE→keys,查看现存的快捷键,也可以配置选择快捷 编辑状态时: Ctrl+Shift+space(默认与输入法冲突,修改 ...

  4. PYTHON资源入口汇总

    Python资源入口汇总 官网 官方文档 教程和书籍 框架 数据库 模板 工具及第三方包 视频 书籍 博客 经典博文集合 社区 其他 整理中,进度30% 官网 入口 官方文档 英文 document ...

  5. python每日一练:0007题

    第 0007 题: 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但是要分别列出来. # -*- coding:utf-8 -*- import os def count ...

  6. [python每日一练]--0012:敏感词过滤 type2

    题目链接:https://github.com/Show-Me-the-Code/show-me-the-code代码github链接:https://github.com/wjsaya/python ...

  7. Python 每日一练 | Flask 实现半成品留言板

    留言板Flask实现 引言 看了几天网上的代码,终于写出来一个半成品的Flask的留言板项目,为什么说是半成品呢?因为没能实现留言板那种及时评论刷新的效果,可能还是在重定向上有问题 或者渲染写的存在问 ...

  8. Python 每日一练(5)

    引言 Python每日一练又开始啦,今天的专题和Excel有关,主要是实现将txt文本中数据写入到Excel中,说来也巧,今天刚好学校要更新各团支部的人员信息,就借此直接把事情做了 主要对于三种数据类 ...

  9. Python 每日一练(4)

    引言 今天继续是python每日一练的几个专题,主要涵盖简单的敏感词识别以及图片爬虫 敏感词识别 这个敏感词的识别写的感觉比较简单,总的概括之后感觉功能可以简略成if filter_words in ...

随机推荐

  1. Appium简介及工作原理

    一.什么是Appium Appium是一个开源.跨平台的测试框架,可以用来测试原生及混合的移动端应用.Appium支持IOS.Android及FirefoxOS平台.Appium使用WebDriver ...

  2. ansible-play中关于标签tages,handler,notify的使用

    --- - hosts: webser remote_user: root tasks: - name: install httpd package yum: name=httpd tages: in ...

  3. 将字符串类型的出生日期转为int类型的年龄

    public static int getAgeByBirthday(String s) { Date birthday = null; SimpleDateFormat format = new S ...

  4. NPOI处理Word文本中段落编号

    NPOI的XWPFParagraph对象中,是无法直接读取段落编号的,然而可以读取的是编号的样式名称(GetNumFmt),编号分组ID(GetNumID),编号样式(NumLevelText)等.具 ...

  5. ./sample_mnist: error while loading shared libraries: libnvinfer.so.4: cannot open shared object file: No such file or directory

    Your library is a dynamic library. You need to tell the operating system where it can locate it at r ...

  6. Nim函数调用的几种形式

    Nim函数调用的几种形式 Nim 转载条件:如果你需要转载本文,你需要做到完整转载本文所有的内容,不得删改文内的作者名字与链接.否则拒绝转载. 关于nim的例行介绍: Nim 是一门静态编译型的系统级 ...

  7. 日积月累--线程中断interrupt()方法

    线程中断方法interrupt()方法的理解: interrupt()方法的源码: interrupted()方法的源码及注解: isInterrupted()方法源码及注解: 在了解这个方法之前我们 ...

  8. Openresty 进行路由系统设计

    1.系统基础设计图为: 用户通过Http访问Openresty(Nginx + Lua), 其中Nginx虚拟主机中配置文件进行Lua脚本加载. LUA通过nginx内置变量或者http请求中变量来区 ...

  9. ViewBag赋值Html格式值

    今天再给自己总结一下,关于ViewBag赋值Html格式值,但是在web页显示不正常; 例如,ViewBag.Content = "<p>你好,我现在测试一个东西.</p& ...

  10. asp.net webapi 生成在线文档--Swagger

    第一步:使用nuget包获取Swashbule.swagger.net.ui的包并安装. 安装成功后 打开App_Start->SwaggerNet.cs 注释掉一下两行 //[assembly ...