python 初级

#
# 定义一个类:MyNum,它包含:
# 1个实例属性:num用户由键盘随机输入一个正整数数字,如:100,将该值作为 MyNum类__init__方法的一个参数传入,并赋给类的实例属性num
#
# 6个实例方法:
# 1)show_num()
# 打印从1到属性num之间所有的数字,如:如果属性num为100,则打印“1 2 3 4 ...99 100”


# 2)calc_sum()
# 计算从1-num之间所有数字的和并输出,如:如果属性num的值为100,则计算 1+2+3+...+99+100的值

# 3)calc_odd_sum()
# 计算从1-num之间所有奇数的和并输出,如:如果属性num的值为100,则计算 1+3+5+7+...+99的值

# 4)calc_even_sum()
# 计算从1-num之间所有偶数的和并输出,如:如果属性num的值为100,则计算 2+4+6+8+...+100的值

# 5)show_num_div()
# 打印出从1-num之间所有能被7整除的数或者包含7的数字,如果找到了输出 例:“找到了 7 , 过”,如果未找到不用输出

# 6)check_num()
# 判断num是否是回文数(即是给定一个数,这个数顺读和逆读都是一样的)并输出 判断结果,
# 如:如果属性num的值为101,则输出“101是回文数”;如果属性 num的值为123,则输出 “123不是回文数”

# 7)show_sanjiao()
# 打印倒三角demo(使用至少三种方法实现)

# 8)replace_item()
# my_list = [1,2,3,4,5] 交换相邻元素,索引为奇数和索引为偶数位置元素 ----》 my_list = [2,1,4,3,5] (要求使用两种方法完成)

# 9) isleap()
# 打印1998--2200年之间的所有闰年(能被4整除但不能被100整除,或者能被400整除的年份)

# 10)定义方法
# 使用两种方法实现99乘法表的输出

# 11)封装方法实现
# 倒着打印99乘法表

# 12)封装一个方法实现模拟演示两个玩家之间的猜拳游戏

# 13)输入数字打印倒三角。
# 案例完成思路要求: 分别通过for循环和while循环

# 14) 使用for循环输出所有三位数的水仙花数?(成立条件:水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。
# (例如:1^3 + 5^3 + 3^3 = 153)
# )

# 15) 使用循环,循环判断1-12月属于哪个季节?(3-5春季,6-8夏季,9-11秋季,12-2冬季)

# 16) 有列表my_list = [3,1,4,6,5,2],先将列表中的元素顺序排列并输出;再将列表中的元素倒序排列并输出。

# 17) 使用键盘随机输入5个整数,添加到列表中,并输出最终列表并展示效果。

# 18) 有列表list = [9,8,7,6,5,4,3,21],删除列表中的最后一个元素并输出,删除列表中的第1个元素并输出列表展示效果,删除列的指定元素5并输出展示效果。


# 19) my_str = “hello world hello python”,使用字符串的常见操作方法,找出该字符串中长度最长的单词并输出展示?


# 20) 有列表my_list = [1,[2,3],[4,5,6[7,8,9]]],使用列表的嵌套的相关知识取出元素8


# 21) my_list = [3,5,7,9,3,5,7],使用集合相关知识完成my_list列表的去重,并输出去重之后的my_list


# 22) my_dict = {“name”:”xiaoming”,”age”:18},分别使用字典的增删改查相关方法完成练习


# 23) list = [1,2,3,4,5,6666,7,8,9],使用python内置函数计算元素个数、最大值、最小值


# 24) 静态初始化一个列表,分别向列表中添加0-10,求和(依次累加数组中的每一个元素)


# 25) 随机输入五个数,存入列表中,取得最大值和最小值

# 26) 随机输入五个数,存入列表中,找到最大值和最小值所在的位置

# 27) 随机输入五个数,存入列表中,将最大值和最小值互换位置

# 28) 将原列表中符合条件的元素存入到新列表,求新列表中的元素的和。


# 29) 随机输入五个数,存入列表中,取得平均值
# 30) 分别使用while嵌套循环和for嵌套循环打印九九乘法表


# 31) 静态初始化一个空列表,分别使用while循环和for循环向该空列表中添加1--100之间的所有整数(循环录入),
# 完成将列表中所有偶数求和,并输出结果;将列表中所有奇数求和,并输出结果;

# 32) 使用函数封装闰年demo:要求使用函数输出指定年份区间的闰年(998-2020年),特别声明使用参数传递年份,并使用格式化输出,输出该区间中的全部闰年

# 33) 请用列表推导式写出一段 Python 代码,实现分组一个 list 里面的元素,比如 [2,4,6,8,10,...100](1--100之间所有偶数)

# 34) 3请用列表推导式写出一段 Python 代码,实现分组一个 list 里面的元素,比如 [1,3,5,7,9,...99](1--100之间所有奇数)

# 35) 使用递归函数实现输出斐波那契数列















# 36) 定义一个类:Person,它用来表示一个人,它包含:
# 2个实例属性:name和age(分别表示一个人的姓名和年龄)
# 用户由键盘随机输入一个字符串和正整数数字,将输入的这两个值作为Person类 __init__方法的两个参数传入,并赋给类的实例属性name和age
#
# 5个实例方法:
# 1)show_my_info()
# 格式化打印出“我是xx,今年xx岁”,姓名和年龄由属性name和age提供


# 2)show_my_birth()
# 打印出我是哪一年出生的,比如今年是2018年,age是10岁,那么可得知我是2008 年出生的,输出“我是2008年出生”


# 3)show_my_life()
# 打印我的成长历程,比如如果我是2008年出生,今年10岁,则打印出类似如下结 果:
# 2008年 出生
# 2009年 1岁
# ...
# 2018年 10岁


# 4)show_leap_year()
# 判断从我出生那一年到今年(2018年),是否含有闰年(能被4整除但不能被100整 除,或者能被400整除的年份),如果有,打印出全部闰年,如果没有,则打印“没 有闰年”

# 5)can_recite()
# 表示我能背诵九九乘法表,打印出倒的9*9乘法表


# 6)can_recitet()
# 实现输出如下图形:
# 1, 9 2, 9 3, 9 4, 9 5, 9 6, 9 7, 9 8, 9 9, 9
# 1, 8 2, 8 3, 8 4, 8 5, 8 6, 8 7, 8 8, 8
# 1, 7 2, 7 3, 7 4, 7 5, 7 6, 7 7, 7
# 1, 6 2, 6 3, 6 4, 6 5, 6 6, 6
# 1, 5 2, 5 3, 5 4, 5 5, 5
# 1, 4 2, 4 3, 4 4, 4
# 1, 3 2, 3 3, 3
# 1, 2 2, 2
# 1, 1

















#
# 定义一个类:MyString,它包含:
# 1个实例属性:mystr用户由键盘随机输入一个英文字符串(只包含英文字母和空 格),如:”I am a student”,将该值作为MyString类__init__方法的一个参数传入,并 赋给类的实例属性mystr
#
# 6个实例方法:
# 1)show_counts()
# 打印出字符串总字符数(包括空格),如:如果属性mystr为”I am a student”,则输 出14
# 2)show_char_counts()
# 打印出打印出字符串包含英文字母的个数(不包括空格),如:如果属性mystr为”I am a student”,则输出11
# 3)show_cap()
# 将字符串中英文字母全部转换成大写并输出

# 4)show_word_counts()
# 统计字符串中单词的个数并输出,如:如果属性mystr为”I am a student”,则输出4

# 5)判断show_last_word_len()
# 计算字符串中最后一个单词的长度,如:如果属性mystr为”I am a student”,则输出7

# 6)show_long_word()
# 找到字符串中长度最长的单词并输出,如:如果属性mystr为”I am a student”,则输 出 “student”




# 定义一个类:MyYear,它包含:
# 1个实例属性:year用户由键盘随机输入一个年份,如:2018,将该值作为MyYear 类__init__方法的一个参数传入,并赋给类的实例属性year
# 4个实例方法:
# 1)show_season()
# 打印该年所有月份,并显示所属季节,如:“1月 冬季 2月 冬季 3月 春季”等



# 2)isleap()
# 打印该年是否是闰年(能被4整除但不能被100整除,或者能被400整除的年份), 如:如果属性year的值为2018,则输出:“2018年不是闰年”



# 3)year_sum()
# 打印从1到该年所在数字之间所有整数的和,如:如果属性year的值为2018,则计 算1+2+3+4+5+...+2018的值并输出结果。



# 4)check_num()
# 判断该年所在数字是否是回文数(即是给定一个数,这个数顺读和逆读都是一样的)并输出判断
# 结果,如:如果属性year的值为2002,则输出“2002是回文数”;如果属性year的值为2018, 则输出“2018不是回文数”。



# class MyNum(object):
# def __init__(self,num):
# self.num=num
# def show_num(self):
# for i in range(1,self.num+1):
# print(i,end=" ")
# print()
# def calc_sum(self):
# sum=0
# for i in range(1,self.num+1):
# sum+=i
# print("1--num之间的和为:%d"%sum)
# def calc_odd_sum(self):
# sum=0
# for i in range(1,self.num+1):
# if i%2!=0:
# sum+=i
# print("1--num之间的奇数和为:%d"%sum)
# def calc_even_sum(self):
# sum=0
# for i in range(1,self.num+1):
# if i%2==0:
# sum+=i
# print("1--num之间的偶数和为:%d"%sum)
# def show_num_div(self):
# for i in range(1,self.num+1):
# if i%7==0 or "7" in str(i):
# print("%d找到了7,过"%i)
# else:
# pass
# def check_num(self):
# if self.num==int(str(self.num)[::-1]):
# print("%d是回文数"%self.num)
# else:
# print("%d不是回文数"%self.num)
# def show_sanjiao(self):
# for i in range(5,0,-1):
# for j in range(1,1+i):
# print("*",end=" ")
# print()

# i=5
# for a in range(5):
# for j in range(1,1+i):
# print("*",end=" ")
# print()
# i-=1

# i=5
# while i>=1:
# j=1
# while j<=i:
# print("*",end=" ")
# j+=1
# print()
# i-=1
# def replace_item(self):
# my_list=[1,2,3,4,5]
# my_alist=[1,2,3,4,5]
# for i in range(len(my_list)):
# if i%2==0 and i==len(my_list)-1:
# pass
# elif i%2==0:
# my_list[i]=my_list[i+1]
# else:
# my_list[i]=my_alist[i-1]
# print(my_list)

# my_list[0],my_list[1]=my_list[1],my_list[0]
# my_list[2],my_list[3]=my_list[3],my_list[2]
# print(my_list)
# def isleap(self):
# for i in range(1998,2201):
# if i%4==0 and i%100!=0 or i%400==0:
# print("%d是闰年"%i)
# def jiujiu(self):
# for i in range(1,10):
# for j in range(1,1+i):
# print(" %d * %d = %-2d "%(j,i,j*i),end=" ")
# print()

# i=1
# while i<=9:
# j=1
# while j<=i:
# print(" %d * %d = %-2d "%(j,i,j*i),end=" ")
# j+=1
# print()
# i+=1
# def daojiujiu(self):
# for i in range(9,0,-1):
# for j in range(1,1+i):
# print(" %d * %d = %-2d "%(j,i,j*i),end=" ")
# print()
# def daosanjiao(self):
# for i in range(5,0,-1):
# for j in range(1,1+i):
# print("*",end=" ")
# print()

# i=5
# while i>=1:
# j=1
# while j<=i:
# print("*",end=" ")
# j+=1
# print()
# i-=1
# def sxh_num(self):
# sxh=[]
# for x in range(1,10):
# for y in range(0,10):
# for z in range(0,10):
# if x**3+y**3+z**3==100*x+10*y+1*z:
# a=100*x+10*y+1*z
# sxh.append(a)
# print(sxh)
# def jijie(self):
# for i in range(1,13):
# if i>=3 and i<=5:
# print("%d月为春季"%i)
# elif i>=6 and i<=8:
# print("%d月为夏季"%i)
# elif i>=9 and i<=11:
# print("%d月为秋季"%i)
# else:
# print("%d月为冬季"%i)
# def list(self):
# my_list=[3,1,4,6,5,2]
# my_list.sort()
# print(my_list)
# my_list.reverse()
# print(my_list)
# def name(self):
# list=[]
# for num in range(5):
# num=int(input("请输入数字:"))
# list.append(num)
# print(list)
# def alist(self):
# list=[9,8,7,6,5,4,3,2,1]
# list.pop()
# print(list)
# del list[0]
# print(list)
# list.remove(5)
# print(list)
# def str(self):
# my_str="hello world hello python"
# ret=my_str.split(" ")
# longest=""
# for i in ret:
# if len(i)>len(longest):
# longest=i
# print(longest)
# def liebiao(self):
# my_list=[1,[2,3],[4,5,6,[7,8,9]]]
# print(my_list[2][1][1])
# def qc(self):
# my_list=[3,5,7,9,3,5,7]
# my_alist=set(my_list)
# my_list=list(my_alist)
# print(my_list)
# def blist(self):
# list=[1,2,3,4,5,6666,7,8,9]
# print(len(list))
# print(max(list))
# print(min(list))
# def jingtai(self):
# alist=list()
# for i in range(10):
# num=int(input("请输入数字:"))
# alist.append(num)
# print(sum(alist))
# def five(self):
# list=[]
# for i in range(5):
# num=int(input("请输入数字:"))
# list.append(num)
# print(max(list))
# print(min(list))
# def zui(self):
# list=[]
# for i in range(5):
# num=int(input("请输入数字:"))
# list.append(num)
# a=max(list)
# b=min(list)
# c=list.index(a)
# d=list.index(b)
# list[c]=b
# list[d]=a
# print(list)
# def new(self):
# alist=[2,4,6,8,"w"]
# blist=[]
# for i in alist:
# if type(i)==int:
# blist.append(i)
# print(sum(blist))
# def set(self):
# list=[]
# for i in range(5):
# num=int(input("请输入数字:"))
# list.append(num)
# print(sum(list)/len(list))
# def cfb(self):
# for i in range(1,10):
# for j in range(1,i+1):
# print(" %d * %d = %-2d "%(j,i,j*i),end=" ")
# print()
# def ret(self):
# alist=list()
# for i in range(1,101):
# alist.append(i)
# print(alist)
# i=0
# while i<=100:
# i+=1
# alist.append(i)
# print(alist)
# sum=0
# for i in range(1,101):
# if i%2==0:
# sum+=i
# print("1--100之间的偶数和为:%d"%sum)
# sum=0
# for i in range(1,101):
# if i%2!=0:
# sum+=i
# print("1--100之间的奇数和为:%d"%sum)
# def run_year(self):
# for i in range(998,2021):
# if i%4==0 and i%100!=0 or i%400==0:
# print("%d年是闰年"%i)
# def python(self):
# print([i for i in range(1,101) if i%2!=0])
# print([i for i in range(1,101) if i%2==0])
# def dg(self):
# def digui(n):
# if n==0:
# return 0
# if n==1:
# return 1
# else:
# return digui(n-1)+digui(n-2)
# for i in range(10):
# print(digui(i))
# m=MyNum(int(input("请输入数字:")))
# m.show_num()
# m.calc_sum()
# m.calc_odd_sum()
# m.calc_even_sum()
# m.show_num_div()
# m.check_num()
# m.show_sanjiao()
# m.replace_item()
# m.isleap()
# m.jiujiu()
# m.daojiujiu()
# m.daosanjiao()
# m.sxh_num()
# m.jijie()
# m.list()
# m.name()
# m.alist()
# m.str()
# m.liebiao()
# m.qc()
# m.blist()
# m.jingtai()
# m.five()
# m.zui()
# m.new()
# m.set()
# m.cfb()
# m.ret()
# m.run_year()
# m.python()
# m.dg()


# class Person(object):
# def __init__(self,name,age):
# self.name=name
# self.age=age
# def show_my_info(self):
# print("我是%s,今年%d岁"%(self.name,self.age))
# def show_my_birth(self):
# year=2018-self.age
# print("我是%d年出生"%year)
# def show_my_life(self):
# year=2018-self.age
# print("我是%d年出生"%year)
# j=0
# for i in range(year+1,2019):
# j+=1
# print("%d年%s岁"%(i,j))
# def show_leap_year(self):
# year=2018-self.age
# alist=[]
# for i in range(year,2019):
# if i%4==0 and i%100!=0 or i%400==0:
# alist.append(i)
# print("%d是闰年"%i)
# if len(alist)==0:
# print("没有闰年")
# def can_recite(self):
# print("%s能背诵九九乘法表"%self.name)
# for i in range(9,0,-1):
# for j in range(1,i+1):
# print(" %d * %d = %-2d "%(j,i,j*i),end=" ")
# print()
# def can_recitet(self):
# for i in range(9,0,-1):
# for j in range(1,i+1):
# print(" %d, %d "%(j,i),end=" ")
# print()
# p=Person(input("请输入姓名:"),int(input("请输入年龄:")))
# p.show_my_info()
# p.show_my_birth()
# p.show_my_life()
# p.show_leap_year()
# p.can_recite()
# p.can_recitet()










# class MyString(object):
# def __init__(self,mystr):
# self.mystr=mystr
# def show_counts(self):
# print(len(self.mystr))
# def show_char_counts(self):
# mystr=self.mystr.replace(" ","")
# print(len(mystr))
# def show_cap(self):
# mystr=self.mystr.upper()
# print(mystr)
# def show_word_counts(self):
# mystr=self.mystr.split(" ")
# print(len(mystr))
# def show_last_word_len(self):
# mystr=self.mystr.split(" ")
# word=mystr[-1]
# print(len(word))
# def show_long_word(self):
# mystr=self.mystr.split(" ")
# longest=""
# for i in mystr:
# if len(i)>len(longest):
# longest=i
# print(longest)

# m=MyString(input("请输入字符串:"))
# m.show_counts()
# m.show_char_counts()
# m.show_cap()
# m.show_word_counts()
# m.show_last_word_len()
# m.show_long_word()



# class MyYear(object):
# def __init__(self,year):
# self.year=year
# def show_season(self):
# for i in range(1,13):
# if i>=3 and i<=5:
# print("%d月为春季"%i)
# elif i>=6 and i<=8:
# print("%d月为夏季"%i)
# elif i>=9 and i<=11:
# print("%d月为秋季"%i)
# else:
# print("%d月为冬季"%i)
# def isleap(self):
# if self.year%4==0 and self.year%100!=0 or self.year%400==0:
# print("%d年是闰年"%self.year)
# else:
# print("%d年不是闰年"%self.year)
# def year_sum(self):
# sum=0
# for i in range(1,self.year+1):
# sum+=i
# print("1--self.year之间的整数和为:%d"%sum)
# sum=0
# for i in range(1,self.year+1):
# if i%2==0:
# sum+=i
# print("1--self.year之间的偶数和为:%d"%sum)
# sum=0
# for i in range(1,self.year+1):
# if i%2!=0:
# sum+=i
# print("1--self.year之间的奇数和为:%d"%sum)
# def check_num(self):
# if self.year==int(str(self.year)[::-1]):
# print("%d是回文数"%self.year)
# else:
# print("%d不是回文数"%self.year)
# m=MyYear(int(input("请输入年份:")))
# m.show_season()
# m.isleap()
# m.year_sum()
# m.check_num()



# class Wyf(object):
# def __init__(self,gsc):
# self.gsc=gsc
# def wenjian(self):
# # f.close()
# f=open("999","w",encoding="utf-8")
# f.write("余生我陪你走,李晓慧")
# f.close()
# w=Wyf(int(input("请输入:")))
# w.wenjian()



# class Person(object):
# def __init__(self,name,age):
# self.name=name
# self.age=age
# def show_my_info(self):
# print("我是%s,今年%d岁"%(self.name,self.age))
# def show_my_birth(self):
# year=2018-self.age
# print("我是%d年出生"%year)
# def show_my_life(self):
# year=2018-self.age
# print("%d年出生"%year)
# j=0
# for i in range(year+1,2019):
# j+=1
# print("%d年%d岁"%(i,j))
# def show_leap_year(self):
# year=2018-self.age
# alist=[]
# for i in range(year,2019):
# if i%4==0 and i%100!=0 or i%400==0:
# print("%d是闰年"%i)
# alist.append(i)
# if len(alist)==0:
# print("没有闰年")
# def can_recite(self):
# print("%s能背诵九九乘法表--倒背如流"%self.name)
# for i in range(1,10):
# for j in range(1,i+1):
# print(" %d * %d = %-2d " %(j,i,j*i),end=" ")
# print()
# print("-"*120)
# for i in range(9,0,-1):
# for j in range(1,i+1):
# print(" %d * %d = %-2d "%(j,i,j*i),end=" ")
# print()
# def make_file(self):
# f=open("baobao.txt","w")
# for i in range(20):
# f.write("hello world hello python \n")
# f.close()
# def check_num(self):
# num=int(input("请输入数字:"))
# if num==int(str(num)[::-1]):
# print("%d是回文数"%num)
# else:
# pass
# def show_num_div(self):
# num=int(input("请输入数字:"))
# for num in range(1,num+1):
# if num%7==0 or "7" in str(num):
# print("找到了%d,过"%num)
# else:
# pass
# def show_long_word(self):
# mystr=input("请输入字符串:")
# ret=mystr.split(" ")
# longest=""
# for i in ret:
# if len(i)>len(longest):
# longest=i
# print(longest)
# def replace_num(self):
# alist=[1,2,3,4,5,66,77,88,9,0,99]
# print(alist)
# for i in range(len(alist)):
# if i%2==0 and i==len(alist)-1:
# pass
# elif i%2==0:
# alist[i],alist[i+1]=alist[i+1],alist[i]
# else:
# pass
# print(alist)
# blist=[1,2,3,4,5,66,77,88,9,0,99]
# for i in range(len(alist)):
# if i%2==0 and i==len(alist)-1:
# pass
# elif i%2==0:
# alist[i]=blist[i+1]
# else:
# alist[i]=blist[i-1]
# print(alist)
# def wenjian(self):
# str=input("请输入:")
# f=open("wyf.txt","w")
# for i in range(10):
# f.write("wangyifei \n")
# f.close()
# p=Person(input("请输入姓名:"),int(input("请输入年龄:")))
# p.show_my_info()
# p.show_my_birth()
# p.show_my_life()
# p.show_leap_year()
# p.can_recite()
# p.make_file()
# p.check_num()
# p.show_num_div()
# p.show_long_word()
# p.replace_num()
# p.wenjian()




# class Person(object):
# def __init__(self, name, age):
# self.name = name
# self.age = age

# def show_my_info(self):
# print("我是%s,今年%d岁" % (self.name, self.age))
# def show_my_birth(self):
# year=2018-self.age
# print("我是%d年出生"%year)
# def show_my_life(self):
# year=2018-self.age
# print("%d年出生"%year)
# j=0
# for i in range(year+1,2019):
# j+=1
# print("%d年%d岁"%(i,j))
# def show_leap_year(self):
# alist=[]
# year=2018-self.age
# for i in range(year,2019):
# if i%4==0 and i%100!=0 or i%400==0:
# alist.append(i)
# print("%d是闰年"%i)
# if len(alist)==0:
# print("没有闰年")
# def can_recite(self):
# print("%s能背诵九九乘法表--倒背如流"%self.name)
#正九九;
# for i in range(1,10):
# for j in range(1,1+i):
# print(" %d * %d = %-2d "%(j,i,j*i),end=" ")
# print()
#倒九九;
# for i in range(9,0,-1):
# for j in range(1,1+i):
# print(" %d * %d = %-2d " %(j,i,j*i),end=" ")
# print()
# def make_file(self):
# f=open("baobao.txt","w")
# for i in range(10):
# f.write("hello world hello python \n")
# f.close()
# def check_num(self):
# num=int(input("请输入数字:"))
# if num==int(str(num)[::-1]):
# print("%d是回文数"%num)
# else:
# pass
# def show_num_div(self):
# num=int(input("请输入数字:"))
# for i in range(1,num):
# if i%7==0 or "7" in str(i):
# print("%d找到了7,过"%i)
# def show_long_word(self):
# str=input("请输入字符串:")
# mystr=str.split(" ")
# longest=""
# for i in mystr:
# if len(i)>len(longest):
# longest=i
# print(longest)
# def replace_num(self):
# alist=[1,2,3,4,5,66,77,88,9,0,99]
# blist=[1,2,3,4,5,66,77,88,9,0,99]
# for i in range(len(alist)):
# if i%2==0 and i==len(alist)-1:
# pass
# elif i%2==0:
# alist[i]=blist[i+1]
# else:
# alist[i]=blist[i-1]
# print(alist)
# p = Person(input("请输入字符串:"), int(input("请输入数字:")))
# p.show_my_info()
# p.show_my_birth()
# p.show_my_life()
# p.show_leap_year()
# p.can_recite()
# p.make_file()
# p.check_num()
# p.show_num_div()
# p.show_long_word()
# p.replace_num()


"""
1.功能描述
"""
# class MyString(object):
# def __init__(self,mystr):
# self.mystr=mystr
# def find_num(self):
# list=[1,4,2,8,7,3,9]
# if 8 in list:
# print(8)
# else:
# print("没找到")
# def show_char_counts(self):
# mystr=self.mystr.replace(" ","")
# print(len(mystr))
# def show_cap(self):
# mystr=self.mystr.upper()
# print(mystr)
# def show_word_counts(self):
# mystr=self.mystr
# ret=mystr.split(" ")
# print(len(ret))
# def show_last_word_len(self):
# mystr=self.mystr.split(" ")
# word=mystr[-1]
# print(len(word))
# def can_recite(self):
# for i in range(1,10):
# for j in range(1,1+i):
# print(j,end=" ")
# j+=i
# print()
# m=MyString(input("请输入字符串:"))
# m.find_num()
# m.show_char_counts()
# m.show_cap()
# m.show_word_counts()
# m.show_last_word_len()
# m.can_recite()


# class MyYear(object):
# def __init__(self,year):
# self.year=year
# def print_str(self):
# Str="Hello Word"
# str=Str.lower()
# print(str)
# def isleap(self):
# if self.year%4==0 and self.year%100!=0 or self.year%400==0:
# print("%d年是闰年"%self.year)
# else:
# print("%d年不是闰年"%self.year)
# def year_sum(self):
# sum=0
# for i in range(1,self.year+1):
# sum+=i
# print("1--self.year之间的整数和为:%d"%sum)
# def can_recite(self):
# for i in range(5,0,-1):
# for j in range(1,1+i):
# print("*",end="")
# print()
# m=MyYear(int(input("请输入年份:")))
# m.print_str()
# m.isleap()
# m.year_sum()
# m.can_recite()



# class MyString(object):
# def __init__(self,mystr):
# self.mystr=mystr
# def show_counts(self):
# mystr=self.mystr
# print(len(mystr))
# def show_char_counts(self):
# mystr=self.mystr.replace(" ","")
# ret=mystr
# print(len(ret))
# def show_cap(self):
# mystr=self.mystr.upper()
# print(mystr)
# def show_word_counts(self):
# mystr=self.mystr.split(" ")
# print(len(mystr))
# def show_last_word_len(self):
# mystr=self.mystr.split(" ")
# word=mystr[-1]
# print(len(word))
# def show_long_word(self):
# mystr=self.mystr.split(" ")
# longest=""
# for i in mystr:
# if len(i)>len(longest):
# longest=i
# print(longest)
# m=MyString(input("请输入字符串:"))
# m.show_counts()
# m.show_char_counts()
# m.show_cap()
# m.show_word_counts()
# m.show_last_word_len()
# m.show_long_word()



# class A(object):
# def __init__(self):
# self.num=10
# def print(self):
# print(self.num+10)
# # a=A()
# # print(a.num)
# # a.print()
# class B(A):
# pass
# b=B()
# print(b.num)
# b.print()

# #单继承;
# class Master(object):
# def __init__(self):
# self.peifang="古法煎饼果子配方"
# def make_cake(self):
# print("按照%s配方制作一份煎饼果子"%self.peifang)
# class Prentice(Master):
# pass
# laoli=Master()
# print(laoli.peifang)
# laoli.make_cake()
# print("*"*30)
# damao=Prentice()
# print(damao.peifang)
# damao.make_cake() ()




# class Master(object):
# def __init__(self):
# self.peifang="古法煎饼果子配方"
#
# def make_cake(self):
# print("按照%s配方制作一份煎饼果子"%self.peifang)
#
# def dayandai(self):
# print("师傅爱抽烟,喜欢大烟袋")
#
# class School(object):
# def __init__(self):
# self.peifang="现代煎饼果子配方"
#
# def make_cake(self):
# print("按照(%s)配方制作一份煎饼果子"%self.peifang)
#
# class Prentice(School,Master):
# pass
#
# damao=Prentice()
# print(damao.peifang)
# damao.make_cake()
# damao.dayandai()
# print(Prentice.__mro__) #顺序表



# class Master(object):
# def __init__(self):
# self.peifang="古法煎饼果子配方"
#
# def make_cake(self):
# print("按照%s配方制作一份煎饼果子"%self.peifang)
#
#
# class School(object):
# def __init__(self):
# self.peifang="现代煎饼果子配方"
#
# def make_cake(self):
# print("按照(%s)配方制作一份煎饼果子"%self.peifang)
#
# class Prentice(School,Master):
# def __init__(self):
# self.peifang="猫氏煎饼果子配方"
# def make_cake(self):
# print("按照(%s)配方制作一份煎饼果子"%self.peifang)
#
# damao=Prentice()
# print(damao.peifang)
# damao.make_cake()
# print(Prentice.__mro__)


# 多继承;
# class Master(object):
# def __init__(self):
# self.peifang="古法煎饼果子配方"
#
# def make_cake(self):
# print("按照《%s》配方制作一份煎饼果子"%self.peifang)
#
# class School(object):
# def __init__(self):
# self.peifang="现代煎饼果子配方"
#
# def make_cake(self):
# print("按照《%s》配方制作一份煎饼果子"%self.peifang)
#
# class Prentice(Master,School):
# def __init__(self):
# self.peifang="猫氏煎饼果子配方"
#
# def make_cake(self):
# print("按照《%s》配方制作一份煎饼果子"%self.peifang)
#
# def make_new_cake(self):
# Master.__init__(self)
# Master.make_cake(self)
#
# def make_old_cake(self):
# School.__init__(self)
# School.make_cake(self)
#
# damao=Prentice()
# damao.make_cake()
# damao.make_new_cake()
# damao.make_old_cake()



#多层继承;
# class Master(object):
# def __init__(self):
# self.peifang="古法煎饼果子配方"
# def make_cake(self):
# print("按照《%s》配方制作一份煎饼果子"%self.peifang)
# class School(Master):
# def __init__(self):
# self.peifang="现代煎饼果子配方"
# def make_cake(self):
# print("按照《%s》配方制作一份煎饼果子"%self.peifang)
# super().__init__()
# super().make_cake()
# class Prentice(School,Master):
# def __init__(self):
# self.peifang="猫氏煎饼果子配方"
# self.money=10000
# def make_cake(self):
# print("按照《%s》配方制作一份煎饼果子"%self.peifang)
#
# def make_old_cake(self):
# School.__init__(self)
# School.make_cake(self)
# def make_new_cake(self):
# Master.__init__(self)
# Master.make_cake(self)
# class PrenticePrentice(Prentice):
# pass
# xiaomao=PrenticePrentice()
# xiaomao.make_cake()
# xiaomao.make_old_cake()
# xiaomao.make_new_cake()
#
# print(xiaomao.money)


#super

# class Master(object):
# def __init__(self):
# self.peifang="古法煎饼果子配方"
# def make_cake(self):
# print("按照《%s》配方制作一份煎饼果子"%self.peifang)
#
#
# class School(Master):
# def __init__(self):
# self.peifang = "现代煎饼果子配方"
#
# def make_cake(self):
# print("按照《%s》配方制作一份煎饼果子" % self.peifang)
# super().__init__()
# super().make_cake()
#
# class Prentice(School,Master):
# def __init__(self):
# self.peifang="猫氏煎饼果子配方"
# def make_cake(self):
# self.__init__()
# print("按照《%s》配方制作一份煎饼果子" % self.peifang)
# def make_all_cake(self):
# School.__init__(self)
# School.make_cake(self)
# Master.__init__(self)
# Master.make_cake(self)
# self.__init__()
# self.make_cake()
#
# if __name__ == '__main__':
#
#
# damao=Prentice()
# damao.make_all_cake()




#私有属性;
# class Master(object):
# def __init__(self):
# self.peifang="古法煎饼果子"
#
# def make_cake(self):
# print("按照(%s)制作一份煎饼果子"%self.peifang)
#
# class School(object):
# def __init__(self):
# self.peifang = "现代煎饼果子"
#
# def make_cake(self):
# print("按照(%s)制作一份煎饼果子" % self.peifang)
#
# class Prentice(Master,School):
# def __init__(self):
# self.peifang="猫氏煎饼果子"
# self.__money=10000000
#
# def __print_money(self):
# print(self.__money)
#
# def run(self):
# self.__print_money()
#
# def getter(self): #获取
# print(self.__money)
#
# def setter(self): #修改
# self.__money=10000
# print(self.__money)
#
# def make_cake(self):
# print("按照(%s)制作煎饼果子配方"%self.peifang)
#
# def make_old_cake(self):
# Master.__init__(self)
# Master.make_cake(self)
#
# def make_new_cake(self):
# School.__init__(self)
# School.make_cake(self)
#
# # class PrenticePrentice(Prentice):
# # pass
#
# damao=Prentice()
# # print(damao.__money)
# # damao.__print_money()
# damao.getter()
# damao.setter()
# damao.run()




"""
多态;通常处理在
(1)发生继承;子继父
(2)子重写父;同名属性/方法
(3)调用子重写父,同名属性/方法
"""
# class F1(object):
# def show(self):
# print("F1.show")
#
# class S1(F1):
# def show(self):
# print("S1.show")
#
# class S2(F1):
# def show(self):
# print("S2.show")
#
# s1=S1()
# s2=S2()
# s1.show()
# s2.show()


# class People(object):
# name="Tom" #共有类属性;
# __age=188 #私有类属性;
# p=People()
# print(p.name)
# print(People.name) #公有的类属性,在类外可以通过类对象和实例对象访问
# print(p.__age)
# print(People.__age) #公有的类属性,在类外可以通过类对象和实例对象访问


class People(object):
address="河南" #类属性
def __init__(self):
self.name="宝宝" #实例属性
self.age=38
if __name__=='__main__': #程序入口
p=People()
# print(p.name)
# print(p.age)
# print(p.address)
# print("*"*30)
# p.age=18
# print(p.age)


# class People(object):
# country="china" #类属性
# print(People.country)
# p=People()
# print(p.country)
# p.country="wojia"
# print(p.country) #实例属性会屏蔽掉同名的类属性
# print(People.country)
# del p.country #删除实例属性
# print(p.country)


# class People(object):
#
# __counry="China"
#
# @classmethod
# def get_country(cls):
# print(cls.__counry)
#
# p=People()
# # print(p.get_country())
# # print(People.get_country())
# p.get_country()
# People.get_country()


#类方法
# class People(object):
# #私有类属性
# __counry="China"
# #类方法,用classmethod来进行修饰
# @classmethod
# def get_country(cls): #获取类的私有属性
# return cls.__counry
# @classmethod
# def set_country(cls,country): #获取类的私有属性
# cls.__counry=country
#
# p=People()
# print(p.get_country())
# print(People.get_country())
# p.set_country("河南驻马店")
# print(p.get_country())
# print(People.get_country())


#静态方法
# class Sun(object):
# name="草原红太阳"
#
# @staticmethod
# def moon():
# return Sun.name
#
# s=Sun()
# print(s.moon())
# print(Sun.moon())
#



# class Sun(object):
# name="阿成"
#
# @staticmethod
# def moon():
# return Sun.name
# sun=Sun()
# print(sun.moon())
# print(Sun.moon())



#__new__方法
# class Dog(object):
# def __new__(cls, *args, **kwargs):
# #__new__必须要有返回值,返回实例化出来的实例,
# # 这点在自己实现__new__时要特别注意,
# # 可以return父类__new__出来的实例,
# # 或者直接是object的__new__出来的实例
# print("__new__()实例")
# return object.__new__(cls)
# def __init__(self):
# print("__init__()方法")
# a=Dog()


# class DanLi(object):
# """ 单例类"""
# a=None
# def __new__(cls,age,name):
# if cls.a is None:
# cls.a=object.__new__(cls)
# return cls.a
# b=DanLi(18,"wangfei")
# c=DanLi(38,"xuyuan")
# d=DanLi(28,"maming")
#
# print(id(b))
# print(id(c))
# print(id(d))
#
# print(b)
# print(c)
# print(d)
#
# b.atk=8888
# print(b.atk)
# print(c.atk)
# print(d.atk)


# try:
# f=open("text.txt")
# f.close()
# except FileNotFoundError:
# print("异常已捕获")


# try:
# name="wangyifei"
# print(age)
# except IOError: #错误的演示;
# print("异常已捕获")

# try:
# name="wangyifei"
# #需要捕获异常的代码
# print(nam)
# #捕获异常
# except Exception as e: #as e ---将捕获的异常保存到e变量中
# print(e)


#
# try:
# name="wangyifei"
# #需要捕获异常的代码
# #捕获异常
# except Exception as e: #as e ---将捕获的异常保存到e变量中
# print(e)
# else:
# print("没有异常")



# try:
# name="weubfv"
# # f=open("text","w")
# f=open("text","r")
# # print(nam)
# except Exception as e:
# print(e)
# #如果没有异常走else
# else:
# print("没有异常")
# #不管有没有异常都会走finally
# finally:
# print("f.close()")
# # f.close()




# import os
# import time
# f=open("1.txt","w")
# f.write("qewefvrfvf")
# f.close()
# with open("2.txt","w") as f:
# f.write("hello")


# from 模块 import 方法;从哪个模块导入哪个方法
# import time
# import socket
# from socket import socket
# from time import sleep
# sleep(5)
# print("88888")


#import1;
# import time
# print("6666")
# time.sleep(10)
# print("999999")
#
# from time import sleep
# sleep(5)
# print("8888")


#import2;
# from time import sleep
# print("666666")
# sleep(5)
# print("8888")


# import mofa
# print(mofa.add2num(1,2))



# alist=[1,2,3,4,5,66,77,88,0]
# max_num=max(alist)
# min_num=min(alist)
# print(max_num,min_num)


# max_num=0
# for i in alist:
# if i>max_num:
# max_num=i
# print(max_num)
#
# min_num=0
# for x in alist:
# if x<min_num:
# min_num=x
# print(min_num)


# alist=[1,2,3,4,5,66,77,88,9,0]
# # print(alist)
# blist=[1,2,3,4,5,66,77,88,9,0]
# for i in range(len(alist)):
# if i%2==0:
# alist[i]=blist[i+1]
# else:
# alist[i]=blist[i-1]
# print(alist)



# my_list=[1,2,3,4,5]
# my_alist=[1,2,3,4,5]
# for i in range(len(my_list)-1):
# if i%2==0:
# my_list[i]=my_alist[i+1]
# else:
# my_list[i]=my_alist[i-1]
# print(my_list)


# alist=[1,2,3,4,5]
# blist=[1,2,3,4,5]
# for i in range(len(alist)-1):
# if i%2==0:
# alist[i]=blist[i+1]
# else:
# alist[i]=blist[i-1]
# print(alist)


# alist[0],alist[1]=alist[1],alist[0]
# alist[2],alist[3]=alist[3],alist[2]
# print(alist)

# class Person(object):
# def __init__(self):
# self.height=185
# self.age=20
#
# def fight(self):
# print("会打架")
#
# def run(self):
# print(id(self))
# print("打不过就跑")
#
# banzhang=Person()
# print(banzhang.height)
# print(banzhang.age)
# banzhang.fight()
# banzhang.run()
#
# print(id(banzhang))
# print("*"*30)
# zhangao=Person()
# print(id(zhangao))
# zhangao.run()

#
# class Hero(object):
# #定义了一个英雄类 可以移动和攻击
# def move(self):
# print("正在快速赶往战场")
#
# def attack(self):
# print("发出一招强有力的暴击")
# #创建对象
# taidamier=Hero()
# #给对象赋值
# taidamier.name="蛮王"
# taidamier.hp=2400
# taidamier.atk=500
# taidamier.armor=150
# #获取对象属性值
# print("%s英雄的血量是%d"%(taidamier.name,taidamier.hp))
# print("%s英雄的攻击力是%d"%(taidamier.name,taidamier.atk))
# print("%s英雄的防御是%d"%(taidamier.name,taidamier.armor))
# #获取实例方法
# taidamier.move()
# taidamier.attack()




# class Hero(object):
# #定义了一个英雄类 可以移动和攻击
# def move(self):
# print("正在快速赶往战场")
#
# def attack(self):
# print("发出一招强有力的暴击")
#
# def info(self):
# print("%s英雄的血量是%d" % (self.name, self.hp))
# print("%s英雄的攻击力是%d" % (self.name, self.atk))
# print("%s英雄的防御是%d" % (self.name, self.armor))
#
# #创建对象
# taidamier=Hero()
# #给对象赋值
# taidamier.name="蛮王"
# taidamier.hp=2400
# taidamier.atk=500
# taidamier.armor=150
# #获取对象属性值
# # print("%s英雄的血量是%d"%(taidamier.name,taidamier.hp))
# # print("%s英雄的攻击力是%d"%(taidamier.name,taidamier.atk))
# # print("%s英雄的防御是%d"%(taidamier.name,taidamier.armor))
# #获取实例方法
# taidamier.move()
# taidamier.attack()
# taidamier.info()



# class Hero(object):
# #定义了一个英雄类 可以移动和攻击
# def __init__(self):
# self.name = "蛮王"
# self.hp = 2400
# self.atk = 500
# self.armor = 150
#
# def move(self):
# print("正在快速赶往战场")
#
# def attack(self):
# print("发出一招强有力的暴击")
#
# def info(self):
# print("%s英雄的血量是%d" % (self.name, self.hp))
# print("%s英雄的攻击力是%d" % (self.name, self.atk))
# print("%s英雄的防御是%d" % (self.name, self.armor))
#
# taidamier=Hero()
#
# taidamier.move()
# taidamier.attack()
# taidamier.info()



# class Hero(object):
# #定义了一个英雄类 可以移动和攻击
# def __init__(self,name,hp,atk,armor):
# self.name = name
# self.hp = hp
# self.atk = atk
# self.armor = armor
#
# def move(self):
# print("正在快速赶往战场")
#
# def attack(self):
# print("发出一招强有力的暴击")
#
# def info(self):
# print("%s英雄的血量是%d" % (self.name, self.hp))
# print("%s英雄的攻击力是%d" % (self.name, self.atk))
# print("%s英雄的防御是%d" % (self.name, self.armor))
#
# taidamier=Hero("蛮王",2600,260,150)
#
# gailun=Hero("盖伦",5000,100,800)
#
# taidamier.move()
# taidamier.attack()
# taidamier.info()
#
# gailun.info()





# class Hero(object):
# #定义了一个英雄类 可以移动和攻击
# def __init__(self,name,hp,atk,armor):
# self.name = name
# self.hp = hp
# self.atk = atk
# self.armor = armor
#
# def move(self):
# print("正在快速赶往战场")
#
# def attack(self):
# print("发出一招强有力的暴击")
#
# def __str__(self):
# return "英雄%s血量%d 攻击力%d 防御值%d"%(self.name,self.hp,self.atk,self.armor)
#
# taidamier=Hero("蛮王",2600,260,150)
#
# gailun=Hero("盖伦",5000,100,800)
#
# taidamier.move()
# taidamier.attack()
# print(taidamier.__str__())
# print(gailun.__str__())
#
# print(Hero.__doc__)



# class SweetPotato(object):
# def __init__(self):
# self.cookedTime=0
# self.cookedString="生的"
# self.condiments=[]
#
# def cook(self,time):
# self.cookedTime += time
# if self.cookedTime>8:
# self.cookedString="已经烤成木炭了"
# elif self.cookedTime>5:
# self.cookedString="已经烤好了"
# elif self.cookedTime>3:
# self.cookedString="半生不熟"
# else:
# self.cookedString="生的"
#
# def addCondiments(self,condiment):
# self.condiments.append(condiment)
#
# def __str__(self):
# msg=self.cookedString+"地瓜"
# if self.condiments==[]:
# msg=msg+"(原味)"
# else:
# msg=msg+"("
# for i in self.condiments:
# msg=msg+i+" "
# msg=msg+")"
# return msg
#
# sp=SweetPotato()
# print(sp.cookedTime)
# print(sp.cookedString)
# print(sp.condiments)
# print("*"*30)
# # sp.cook(1)
# # print(sp.cookedString)
# # sp.cook(1)
# # print(sp.cookedString)
# # sp.cook(1)
# # print(sp.cookedString)
# # sp.cook(1)
# # print(sp.cookedString)
# # sp.cook(1)
# # print(sp.cookedString)
# # sp.cook(1)
# # print(sp.cookedString)
# # sp.cook(1)
# # print(sp.cookedString)
# sp.cook(7)
# print(sp.cookedString)
# sp.addCondiments("孜然味")
# print(sp)



#父类;
# class A(object):
# def __init__(self):
# self.num=10
# def print_num(self):
# print(self.num+10)
# class B(A):
# pass
# b=B()
# print(b.num)
# b.print_num()

#子类重写父类的同名属性和方法;
# class Master(object):
# def __init__(self):
# self.kongfu="古法煎饼果子配方"
# def make_cake(self):
# print("古法按照%s制作了一份煎饼果子"%self.kongfu)
# class School(object):
# def __init__(self):
# self.kongfu="现代煎饼果子配方"
# def make_cake(self):
# print("现代按照%s制作了一份煎饼果子"%self.kongfu)
# class Prentice(School,Master):
# def __init__(self):
# self.kongfu="猫氏煎饼果子配方"
# def make_cake(self):
# print("猫氏按照%s制作了一份煎饼果子"%self.kongfu)
# damao=Prentice()
# print(damao.kongfu)
# damao.make_cake()
# print(Prentice.__mro__)



"""
定义函数的格式如下:

def函数名():
代码

"""


# def fozu():
# print(" _ooOoo_ ")
# print(" o8888888o ")
# print(" 88 . 88 ")
# print(" (| -_- |) ")
# print(" O\\ = /O ")
# print(" ____/`---'\\____ ")
# print(" . ' \\| |// `. ")
# print(" / \\||| : |||// \\ ")
# print(" / _||||| -:- |||||- \\ ")
# print(" | | \\\\\\ - /// | | ")
# print(" | \\_| ''\\---/'' | | ")
# print(" \\ .-\\__ `-` ___/-. / ")
# print(" ___`. .' /--.--\\ `. . __ ")
# print(" ."" '< `.___\\_<|>_/___.' >'"". ")
# print(" | | : `- \\`.;`\\ _ /`;.`/ - ` : | | ")
# print(" \\ \\ `-. \\_ __\\ /__ _/ .-` / / ")
# print(" ======`-.____`-.___\\_____/___.-`____.-'====== ")
# print(" `=---=' ")
# print(" ")
# print(" ............................................. ")
# print(" 佛祖镇楼 BUG辟易 ")
# print(" 佛曰: ")
# print(" 写字楼里写字间,写字间里程序员; ")
# print(" 程序人员写程序,又拿程序换酒钱。 ")
# print(" 酒醒只在网上坐,酒醉还来网下眠; ")
# print(" 酒醉酒醒日复日,网上网下年复年。 ")
# print(" 但愿老死电脑间,不愿鞠躬老板前; ")
# print(" 奔驰宝马贵者趣,公交自行程序员。 ")
# print(" 别人笑我忒疯癫,我笑自己命太贱; ")
# print(" 不见满街漂亮妹,哪个归得程序员?")
# fozu()


# def i():
# name="王一妃"
# age=18
# print("姓名:%s 年龄:%d"%(name,age))
# i()


# def my_name(x,y):
# print(x+y)
# my_name(1,2)
# print(help(my_name))

# def add2num():
# a=10
# b=20
# c=a+b
# print(c)
# add2num()

# def add2num(a,b): #函数定义时,所传的参数--形参;
# c=a+b
# print(c)
# add2num(10,20) #调用函数时,所传的参数--实参;


# def add2num(a,b):
# c=a+b
# print(c)
# add2num(10,20)

# def add2num(a,b):
# c=a+b
# return(c)
# print(add2num(10,20))


# def add2num(a,b):
# c=a+b
# return(c)
# ret=add2num(10,20)
# print(ret)

# 函数类型:
# 无参数,无返回值;
# def printMenu():
# print('--------------------------')
# print(' xx涮涮锅 点菜系统')
# print('')
# print(' 1. 羊肉涮涮锅')
# print(' 2. 牛肉涮涮锅')
# print(' 3. 猪肉涮涮锅')
# print('--------------------------')
# printMenu()

# 无参有返
# def add2num():
# a=10
# b=20
# return(a+b)
# ret=add2num()
# print(ret)


# 有参无返
# def add2num(a,b):
# print(a+b)
# add2num(10,20)


# 有参有返
# 计算1--num的累积和;
# def addnum(num):
# i=1
# sum=0
# while i<=num:
# sum+=i
# i+=1
# return sum
# print(addnum(100))


# def sum():
# a=10
# b=20
# c=30
# return(a+b+c)
# ret=sum()
# print(ret)


# def number():
# print("hello world hello python")
# number()



# def add2num(a,b):
# print(a+b)
# add2num(1,2)


# def add2num(a,b):
# c=a+b
# return c
# print(add2num(3,3))


# 函数嵌套;
# def name():
# print("name---开始执行")
# print("hello word")
# print("name---结束执行")
#
#
# def age():
# print("age---开始执行")
# name()
# print("age---结束执行")
#
# age()




#局部变量;
# def func1():
# a=100
# print("func1最初局部变量a的值为:%d" % a)
# a=200
# print("func1改变之后局部变量a的值为:%d" % a)
# def func2():
# a=300
# print("func2最初局部变量a的值为:%d" % a)
# func1()
# func2()


#全局变量;
# a=100
# def func1():
# print(a)
# def func2():
# print(a)
# func1()
# print("*"*20)
# print(a)
# print("*"*20)
# func2()


# a=300
# def func1():
# a=100
# print(a)
# print(a)
# func1()


"""
当函数内出现局部变量和全局变量相同名字时,函数内部中的
变量名 = 数据 此时理解为定义了一个局部变量,而不是修改全局变量的值

"""

#global声明修改全局变量只能用于函数内,否则报错;
# a=600
# def func():
# global a
# a=666
# print(a)
# func()
# print(a)

# a=600
# b=800
# def func():
# global a,b
# a=666
# b=888
# print(a)
# print(b)
# func()
# print(a)
# print(b)

# def func1():
# return 50
# def func2(num):
# print(num)
# ret=func1()
# func2(ret)

# def func1():
# return 50
# def func2():
# ret=func1()
# print(ret)
# func2()





# 一个函数中可以有多个return语句,但是只要有一个return语句被执行到,
# 那么这个函数就会结束了,因此后面的return没有什么用处
#return 返回值;结束函数;
# def func1():
# return 1
# return 2
# def func2():
# ret=func1()
# print(ret)
# func2()

# def func(num):
# if num>100:
# return num+1
# else:
# return num-1
# ret=func(999)
# print(ret)


# def func(a,b):
# shang=a//b
# yushu=a%b
# return shang,yushu
#
# shang,yushu=func(10,20)
# print(shang)
# print(yushu)

# def func():
# return [1,2,3,4,5]
# ret=func()
# print(ret)
#
# def func():
# return (1,2,3,4,5)
# ret=func()
# print(ret)
#
# def func():
# return {"name":"laowang","age":18}
# ret=func()
# print(ret)
#
# def func():
# return {1,2,3,3,4,5}
# ret=func()
# print(ret)

#缺省参数
# def printinfo(name,age=20):
# print("name:%s"%name)
# print("age:%d"%age)
#
# printinfo(name="banzhang")
# print("*"*20)
# printinfo(name="baobao",age=18)


#不定长参数;
# def func(a,b,*args,**kwargs):
# return
# func(1,2,3,4,5)

# def func(a,b,*args,**kwargs):
# print("a=%d"%a)
# print("b=%d"%b)
# print("args:")
# print(args)
# print("kwargs:")
# print(kwargs)
#
# func(1,2,12,34,56,m=666,n=888,p=999)




# def func(a,b,*args,**kwargs):
# print("a=%d"%a)
# print("b=%d"%b)
# print("args:")
# print(args)
# print("kwargs:")
# for key,value in kwargs.items():
# print("key=%s"%value)
#
# c=(3,4,5)
# d={"m":6,"n":7,"p":8}
# func(1,2,*c,**d)



#拆包
# def func():
# high=160
# weight=100
# age=18
# return high,weight,age
# a,b,c=func()
# print("a=%d"%a)
# print("b=%d"%b)
# print("c=%d"%c)

# a,b=[1,2]
# c,d=(3,4)
# print("a=%d"%a)
# print("b=%d"%b)
# print("c=%d"%c)
# print("d=%d"%d)



#交换变量的值;

# a=4
# b=5
#
#
# c=a
# a=b
# b=c
# print("a=%d"%a)
# print("b=%d"%b)



# a=4
# b=5
#
# a=a+b #a=9
# b=a-b #b=4
# a=a-b #a=5
# print("a=%d"%a)
# print("b=%d"%b)


# a,b=4,5
# print(a,b)
# a,b=b,a
# print(a,b)


#引用;
# a=1
# b=a
# print(b)
# a=11
# print(b)
#
# a=[1,2]
# b=a
# print(b)
# a.append(3)
# print(b)

#id
# a=1
# b=a
# print(b)
# a=11
# print(b)
# print(id(a))
# print(id(b))
#
# a=[1,2]
# b=a
# print(b)
# a.append(3)
# print(b)
# print(id(a))
# print(id(b))

# a=[1,2]
# b=a
# print(id(a))
# print(id(b))
# a.append(666)
# print(id(a))
# print(id(b))



#函数作用域,只能在局部变量中使用;
# def func1():
# a=10
# print(a)
# def func2():
# a=20
# print(a)
# func1()
# func2()


"""
列表推导式;
a=[i for i in range(1,6)]
p(a)
"""
# a=[i for i in range(1,6)]
# print(a)
#
# print([i for i in range(1,101) if i%2==0])
# print(sum([i for i in range(1,101) if i%2==0]))
# print(len([i for i in range(1,101) if i%2==0]))



#要保存的数据
# print([100*x+10*y+z*1 for x in range(1,10) for y in range(0,10) for z in range(0,10) if x**3+y**3+z**3==100*x+10*y+z*1])
#
# sxh=[]
# for x in range(1,10):
# for y in range(0,10):
# for z in range(0,10):
# if x**3+y**3+z**3==100*x+10*y+z*1:
# a=100*x+10*y+z*1
# sxh.append(a)
# print(sxh)


# sxh=[]
# for x in range(1,10):
# for y in range(0,10):
# for z in range(0,10):
# if x**3+y**3+z**3==100*x+10*y+1*z:
# a=100*x+10*y+1*z
# sxh.append(a)
# print(sxh)

#print([100*x+10*y+1*z for x in range(1,10) for y in range(0,10) for z in range(0,10) if x**3+y**3+z**3==100*x+10*y+1*z])


#1--100偶数;
# a=[i for i in range(1,101) if i%2==0]
# print(a)
#奇数;
#b=[i for i in range(1,101) if i%2!=0]
#print(b)

# c=[i for i in range(1,20,4)]
# print(c)

# a=[sum for i in range(1,101) if i%2==0 sum+=1 i+=1]
# print(a)



# print("\n".join([i*"*" for i in range(1,6)]))
# print("\n".join([i*"*" for i in range(5,0,-1)]))

#列表推导式三个for用法;
#print([(x,y,z) for x in range(1,3) for y in range(4,6) for z in range(7,9)])


# my_list=[1,1,2,3,4,3,3,3,66]
# print(list(set(my_list)))

# my_tuple=(1,2,2,3,3,4,5,6,11,11,22,22,33,33)
# print(my_tuple)
# set2=set(my_tuple)
# print(set2)
# my_tuple=tuple(set2)
# print(my_tuple)




#匿名函数:对一些函数名进行简写;
#格式:lambda 形参:表达式(返回值或者输出内容)
# f=lambda a,b:a+b
# print(f(10,20))

#有参数无返回值;
# def add2num(a,b):
# print(a+b)
# f=lambda a,b:print(a+b)
# f(10,20)
# print("*"*30)
# add2num(10,20)

#无参有返;
# def add2num():
# return 50
# f=lambda:50
# print(f())
# print("*"*30)
# print(add2num())


#递归:在函数内部调用;
# def digui(n):
# if n==1:
# return 1
# else:
# return n * digui(n-1)
#
# print(digui(1))


"""
斐波那契数列
"""
# def num(n):
# if n==0:
# return 0
# if n==1:
# return 1
# else:
# return num(n-1)+num(n-2)
# for i in range(200):
# print(num(i))


"""
闰年;
(1)键盘输入年份;
(2)for(998-2203);
"""
# (1)
# def run_year():
# i=int(input("请输入年份:"))
# if (i%4==0 and i%100!=0) or i%400==0:
# print("%d是闰年"%i)
# else:
# print("不是闰年")
# run_year()

# (2)
# def run_year():
# for i in range(998,2204):
# if (i%4==0 and i%100!=0) or i%400==0:
# print("%d是闰年"%i)
# else:
# print("%d不是闰年"%i)
# run_year()


"""
2.回文数
"""
# def num():
# for i in range(100,1000):
# if str(i)==str(i)[::-1]:
# print("%d是回文数"%i)
# num()




"""
3.my_str="hello world hello python";
分别封装:
(1)求最后一个单词长度;
(2)求长度最长的单词;
"""
#(1)
# def num():
# my_str="hello world hello python"
# ret=my_str.split(" ")
# print(ret)
# print(len(ret[-1]))
# num()

# (2)
# def ret():
# my_str="hello world hello python"
# ret=my_str.split(" ")
# print(ret)
# longest=""
# for i in ret:
# if len(i)>len(longest):
# longest=i
# print(longest)
# ret()


"""
4.逢七必过;
"""
# def qi():
# for i in range(1,101):
# if i%7==0 or "7" in str(i):
# print("%d逢七必过"%i)
# qi()


"""
5.倒三角;99乘法表;
"""
# def dao():
# i=5
# for a in range(5):
# for j in range(1,1+i):
# print("*",end=" ")
# print()
# i-=1
# dao()

#无参无返;
# def num():
# i=9
# for a in range(9):
# for j in range(1,1+i):
# print(" %d*%d=%-2d "%(j,i,j*i),end=" ")
# print()
# i-=1
# num()

#有参有返;
# def nine(a,b):
# for i in range(a,b):
# for j in range(1,1+i):
# print(" %d*%d=%-2d "%(j,i,j*i),end=" ")
# print()
# i+=1
# return a,b
# nine(1,10)

#有参无返;
# def nine(a,b):
# for i in range(a,b):
# for j in range(1,1+i):
# print(" %d*%d=%-2d "%(j,i,j*i),end=" ")
# print()
# i+=1
# nine(1,10)

#无参有返;
# def nine():
# for i in range(1,10):
# for j in range(1,1+i):
# print(" %d*%d=%-2d "%(j,i,j*i),end=" ")
# print()
# i+=1
# return
# nine()

#倒99;
def nine():
for i in range(9,0,-1):
for j in range(1,1+i):
print(" %d*%d=%-2d "%(j,i,j*i),end=" ")
print()
return
nine()




# def func():
# a=10
# b=20
# c=a+b
# return c
# # func()
# def func1():
# ret=func()/2
# return ret
# set=func1()
# print(set)




# def nine(a,b):
# for i in range(a,b):
# for j in range(1,1+i):
# a = print(" %d*%d=%-2d "%(j,i,j*i),end=" ")
# print()
# i-=1
# return a
# nine(1,10)



# class timu1(object):
# def year1(self):
# i = int(input("请输入年份:"))
# if i % 4 == 0 and i % 100 != 0 or i % 400 == 0:
# print("%d是闰年" % i)
# else:
# print("%d不是闰年" % i)
# def year2(self):
# alist = list()
# for i in range(2009,2012):
# if i % 4 == 0 and i % 100 != 0 or i % 400 == 0:
# alist.append(i)
# print("%d是闰年" % i)
# if len(alist) == 0:
# print("没有闰年")
# def num(self):
# for i in range(100,1000):
# if i == int(str(i)[::-1]):
# print("%d是回文数" % i)
# else:
# pass
# def num1(self):
# i = int(input("输入数字:"))
# if i % 7 == 0 or "7" in str(i):
# print("找到了,过")
# else:
# print(i)
# def str1(self):
# my_str = "hello world hello python"
# my_str1 = my_str.split(" ")
# a = len(my_str1[-1])
# print(a)
# def str2(self):
# my_str = "hello world hello python"
# my_str1 = my_str.split(" ")
# longest = ""
# for i in my_str1:
# if len(i) > len(longest):
# longest = i
# print(longest)
# def num_sanjiao(self):
# for i in range(5,0,-1):
# for j in range(1,i+1):
# print("* ",end='')
# print()
# def num_99(self):
# for i in range(9,0,-1):
# for j in range(1,i+1):
# print("%d * %d = %-4d" %(j,i,j*i),end='')
# print()
#
# timu=timu1()
# timu.year1()
# timu.year2()
# # timu.num()
# # timu.num1()
# # timu.str1()
# # timu.str2()
# # timu.num_sanjiao()
# # timu.num_99()


# f=open("text.txt","w",encoding="utf-8")
# f.write("我额")
# content=f.readline()
# print(type(content))
# i=1
# for temp in content:
# print("王一妃")
# i+=1
# f.close()



# f=open("text.txt","w")
# for i in range(6):
# f.write("hello world,i am here \n")
#
# f.close()


# f=open("text,txt","r")
# data=f.read(10)
# print(data)
#
# data2=f.read()
# print(data2)

# readlines读取全部数据;
# f=open("text.txt")
# data=f.readlines()
# print(data)
# for x,y in enumerate(data):
# print(x,y)
# f.close()

# readline读取一行;
# f=open("text.txt")
# data=f.readline()
# print(data)
# data=f.readline()
# print(data)

#文件重命名;os.rename
# f=open("吉利大学.txt","w")
# f.close()
import os
# os.rename("吉利大学.txt","清华大学.txt")


#1.remove删除文件夹
# os.remove("清华大学.txt")


#2.创建文件夹
# import os
# os.mkdir("张三")

#3.删除文件夹

# os.mkdir("许愿")
# os.rmdir("许愿")

#4.获取当前目录;
# print(os.getcwd())


#5.改变默认目录;
# os.chdir("../")
# print(os.getcwd)

#6.获取目录列表;
# print(os.listdir("./"))
# print(os.listdir("../"))

# old_file_name=input("请输入老文件名:")
# a=open(old_file_name,"w")
# for i in range(10):
# a.write("123456\n")
# a.close()
# num=old_file_name.rfind(".")
# if num>0:
# houzhui=old_file_name[num::]
# file_name=old_file_name[:num:]
# new_file_name=file_name+"[复件]"+houzhui
# f=open(old_file_name,"rb")
# n=open(new_file_name,"wb")
# for i in f.readlines():
# n.write(i)
# f.close()
# n.close()



# str=input("请输入:")
# f=open("文件名.txt","w")
# f.write("yf")
# f.close()










































posted on 2019-05-29 21:25 女己。 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/wyf2019/p/10946360.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值