1.写函数,计算传入字符串中【数字】、【字母】、【空格】、以及【其他】的个数,并返回结果。

def day06_1(s):
dic = {'num': 0, 'alpha': 0, 'space': 0, 'other': 0}
for i in s:
if i.isdigit():
dic['num'] += 1
elif i.isalpha():
dic['alpha'] += 1
elif i.isspace():
dic['space'] += 1
else:
dic['other'] += 1
return dic print(day06_1('sdfjiosdf34430f=-=df'))

2.“一个程序读入三个整数。把此三个数值看成是一个三角形的三个边。这个程序要打印出信息,说明这个三角形是三边不等的、是等腰的、还是等边的。”

a = int(input('请输入一个整数:'))
b = int(input('请输入一个整数:'))
c = int(input('请输入一个整数:'))
if (a + b > c and a - b < c) and (a + c > b and a - c < b) and (b + c > a and b - c < a):
if a == b and a == c and b == c:
print("由{}、{}、{}组成的三角形是等边三角形".format(a, b, c))
elif a == b or a == c or b == c:
print("由{}、{}、{}组成的三角形是等腰三角形".format(a, b, c))
else:
print("由{}、{}、{}组成的三角形是三边不等的三角形".format(a, b, c))
else:
print("由{}、{}、{}这三个数不能组成一个三角形".format(a, b, c))

3.假设商店货品价格(R)皆不大于100元(且为整数),若顾客付款在100元内 (P) ,求找给顾客最少货币个(张)数?(货币面值50元10 元,5 元,1元四 种 ).

price = int(input('请输入商品的价格:'))
money = int(input('请输入您给的钞票面值:'))
change = money - price
num = 0
while change >= 50:
num += 1
change -= 50
while change >= 10:
num += 1
change -= 10
while change >= 5:
num += 1
change -= 5
while change >= 1:
num += 1
change -= 1
print(num)

4.某城市电话号码由三部分组成。它们的名称和内容分别是:

(1)地区码:空白或三位数字;

(2)前 缀:非'0'或'1'的三位数字;

(3)后 缀:4位数字。

假定被测程序能接受一切符合上述规定的电话号码,拒绝所有不符合规定的电话号码。

s = 0
phone = input('请输入电话号码:')
if phone.isdigit():
if len(phone) == 10:
for i in phone[3:6]:
if i in ['', '']:
print("你输入的电话号码不符合前缀为非0或非1的规则")
break
else:
s += 1
if s == 3:
print("你输入的电话号码符合规则")
elif len(phone) == 7:
for i in phone[0:3]:
if i in ['', '']:
print("你输入的电话号码不符合前缀为非0或非1的规则")
break
else:
s += 1
if s == 3:
print("你输入的电话号码符合规则")
else:
print("电话号码只能是10位数字或7位数字")
else:
print('对不起,电话号码只能由数字组成')

5.程序有三个输入变量month、day、year(month 、 day和year均为整数值,并且满足:1≤month≤12和1≤day≤31),分别作为输入日期的月份、日、年份,通过程序可以输出该输入日期在日历上隔一天的日期。例如,输入为 2004 年11月29日,则该程序的输出为2004年12月1日。

year = input('请输入年份:')
month = input('请输入月份:')
day = input('请输入日期:')
if year.isdigit() and month.isdigit() and day.isdigit():
year = int(year)
month = int(month)
day = int(day)
if month <= 12 and day <= 31:
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
if month in [1, 3, 5, 7, 8, 10, 12]:
if day + 2 <= 31:
print("{}年{}月{}日".format(year, month, day + 2))
elif day + 2 == 32: #
if month < 12:
print("{}年{}月{}日".format(year, month + 1, day - 29))
else:
print("{}年{}月{}日".format(year + 1, month - 11, day - 29))
elif day + 2 == 33: #
if month < 12:
print("{}年{}月{}日".format(year, month + 1, day - 29))
else:
print("{}年{}月{}日".format(year + 1, month - 11, day - 29))
elif month == 2:
if day + 2 <= 29:
print("{}年{}月{}日".format(year, month, day + 2))
elif day + 2 == 30: #
print("{}年{}月{}日".format(year, month + 1, day - 27))
elif day + 2 == 31: #
print("{}年{}月{}日".format(year, month + 1, day - 27))
else:
if day + 2 <= 30: #
print("{}年{}月{}日".format(year, month, day + 2))
elif day + 2 == 31: #
print("{}年{}月{}日".format(year, month + 1, day - 28))
elif day + 2 == 32: #
print("{}年{}月{}日".format(year, month + 1, day - 28)) else:
if month in [1, 3, 5, 7, 8, 10, 12]:
if day + 2 <= 31:
print("{}年{}月{}日".format(year, month, day + 2))
elif day + 2 == 32: #
if month < 12:
print("{}年{}月{}日".format(year, month + 1, day - 29))
else:
print("{}年{}月{}日".format(year + 1, month - 11, day - 29))
elif day + 2 == 33: #
if month < 12:
print("{}年{}月{}日".format(year, month + 1, day - 29))
else:
print("{}年{}月{}日".format(year + 1, month - 11, day - 29))
elif month == 2:
if day + 2 <= 28:
print("{}年{}月{}日".format(year, month, day + 2))
elif day + 2 == 29: #
print("{}年{}月{}日".format(year, month + 1, day - 26))
elif day + 2 == 30: #
print("{}年{}月{}日".format(year, month + 1, day - 26))
else:
if day + 2 <= 30: #
print("{}年{}月{}日".format(year, month, day + 2))
elif day + 2 == 31: #
print("{}年{}月{}日".format(year, month + 1, day - 28))
elif day + 2 == 32: #
print("{}年{}月{}日".format(year, month + 1, day - 28)) else:
print("你输入的月份或年份不符合规则")
else:
print("你输入的年份月份或日期不符合规则。 注:只能是数字")

Python练习六的更多相关文章

  1. 简学Python第六章__class面向对象编程与异常处理

    Python第六章__class面向对象编程与异常处理 欢迎加入Linux_Python学习群  群号:478616847 目录: 面向对象的程序设计 类和对象 封装 继承与派生 多态与多态性 特性p ...

  2. 初学Python(六)——输入输出

    初学Python(六)——输入输出 初学Python,主要整理一些学习到的知识点,这次是输入输出. 输入: # -*- coding:utf-8 -*- ''''' python中的输出为print ...

  3. 孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2

    孤荷凌寒自学python第六十九天学习并实践beautifulsoup对象用法2 (完整学习过程屏幕记录视频地址在文末) 今天继续学习beautifulsoup对象的属性与方法等内容. 一.今天进一步 ...

  4. 孤荷凌寒自学python第六十八天学习并实践beautifulsoup模块1

    孤荷凌寒自学python第六十八天学习并实践beautifulsoup模块1 (完整学习过程屏幕记录视频地址在文末) 感觉用requests获取到网页的html源代码后,更重要的工作其实是分析得到的内 ...

  5. 孤荷凌寒自学python第六十七天初步了解Python爬虫初识requests模块

    孤荷凌寒自学python第六十七天初步了解Python爬虫初识requests模块 (完整学习过程屏幕记录视频地址在文末) 从今天起开始正式学习Python的爬虫. 今天已经初步了解了两个主要的模块: ...

  6. python练习六十三:文件处理,读取文件内容,按内容生成文件

    python练习六十三:文件处理 假设要读取code.txt文件中内容,code.txt文件内容如下 01 CN Chinese 02 US United States of America 03 J ...

  7. python练习六十一:文件处理,读取文件内容

    python练习六十一:文件处理,读取文件内容 假设要读取text.txt文件中内容 写文件(如果有文件,那直接调用就行,我这里自己先创建的文件) list1 = ['python','jave',' ...

  8. 孤荷凌寒自学python第六十六天学习mongoDB的基本操作并进行简单封装5

    孤荷凌寒自学python第六十六天学习mongoDB的基本操作并进行简单封装5并学习权限设置 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第十二天. 今天继续学习mongo ...

  9. 孤荷凌寒自学python第六十五天学习mongoDB的基本操作并进行简单封装4

    孤荷凌寒自学python第六十五天学习mongoDB的基本操作并进行简单封装4 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第十一天. 今天继续学习mongoDB的简单操作 ...

  10. 孤荷凌寒自学python第六十四天学习mongoDB的基本操作并进行简单封装3

    孤荷凌寒自学python第六十四天学习mongoDB的基本操作并进行简单封装3 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第十天. 今天继续学习mongoDB的简单操作, ...

随机推荐

  1. ES6 中 Promise

    在说Promise之前我们先简单说一下什么是同步异步? 同步(Sync):所谓同步,就是发出一个功能调用时,在没有得到结果之前,该调用就不返回或继续执行后续操作. 异步(Async):异步与同步相对, ...

  2. Java——重写

    重写面向对象编程的三大特征之一 1.子类重写了父类的方法,则使用子类创建的对象调用该方法时,调用的是重写后的方法,即子类中的方法 2.子类重写父类方法需满足以下条件: (1)方法名和参数列表: 子类重 ...

  3. Python基础-Python的三元运算符和lambda表达式

    1. Python的三元表达式: 现在大部分高级语言都支持 “?”这个三元运算符,它对应的表达式如下:condition ? value if true:value if else 但是 Python ...

  4. CentOS7.6配置do.cker和K.B.S

     方法一: 节点及功能 主机名 IP Master.etcd.registry K8s-01 10.8.8.31 Node1 K8s-02 10.8.8.32 Node2 K8s-03 10.8.8. ...

  5. spring jpa 语法

    摘自http://www.cnblogs.com/BenWong/p/3890012.html Table 2.3. Supported keywords inside method names Ke ...

  6. 本地pip 源搭建起来

    pip install pip2pi pip2tgz target_dir -r requirement.txt 下载想要的本地的py包  /usr/local/python3/bin/dir2pi ...

  7. The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

    今天用mysql连接数据库时,出现The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than o ...

  8. C# 事件 解析

    1.什么是事件,事件和委托什么关系? 事件?事件,就是,比如按一个按钮,弹出你好对话框,就是一个事件. 事件和委托? 事件就是委托的一种呀,委托可以理解为回调机制,回调函数. 2. 怎么理解C#事件, ...

  9. oo第3次博客作业

    一.规格化设计的发展历史 20世纪60年代,软件出现严重的危机Dijkstra提出了goto语句的危害,由此引发了软件界长达数年的论战,并产生了结构化的程序设计方法.随着计算机 技术的发展,结构设计化 ...

  10. NodeJs 设置跨域后页面全部变成了源码在浏览器上显示

    百度搜索跨域后得到 app.all('*', function(req, res, next) { res.header("Access-Control-Allow-Origin" ...