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. PC/FORTH 下的多任务使用

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  2. Forth 内部解释程序工作流程

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  3. JAVAEE第三周

    2.背景:看到Session时,感到很熟悉,毕竟涉及到过类似的编程,用得最多的地点就是保存客户端的信息和记录,比如说你已经登陆过某个网站,下次访问时不想要麻烦的重新登陆你就就可以使用这个机制.Sess ...

  4. reinterpret_cast

    reinterpret_cast强制类型转换符 用法: new_type a = reinterpret_cast <new_type> (value) 将value的值转成new_typ ...

  5. PTA-栈(括弧匹配)

    #include<bits/stdc++.h> using namespace std; #define STACK_INIT_SIZE 10000 #define STACKINCREM ...

  6. mybatis(3)---传参数的方法

    1.传一个参数 //接口方法List<EmpVo> find(int empId); //xml配置 <select resultType="com.ht.mapper.E ...

  7. python网络基础_socket

    利用基本的Socket 通信,模仿远程cmd命令: Server import socket sk = socket.socket() sk.bind(('127.0.0.1',8090)) sk.l ...

  8. call Apply bind详解

    call方法: 语法:call(thisObj,'',''........) 定义:调用一个对象的一个方法,以另一个对象替换当前对象 说明:call方法可以用来代替另一个对象调用一个方法.call方法 ...

  9. Prime ring problem,递归,广搜,回溯法枚举,很好的题

    题目描述: A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each ...

  10. filter以及reduce的用法

    简单的写了就几个例子 # 删掉偶数 li = [1,2,3,4,5,6,7,8,9,10] print(list(filter( lambda x : not x % 2 ==0 ,li))) #保留 ...