Skip to content

Commit 647302e

Browse files
committed
new
1 parent bbba72d commit 647302e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1325
-0
lines changed

old/cases/book_case01_字符串.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name="nik colt"
2+
3+
print(name) #print自带换行
4+
print(name.title())
5+
print(name.upper()+"\n") # \n 换行
6+
print("Hello,"+name.title()+"!\n") #拼接字符串
7+
8+
print("a\tb\tc\td\t") # \t 制表
9+
print("a\tb\tc\td\t\n")
10+
print("a\tb\tc\td\t")
11+
print("a\tb\tc\td\t")
12+
13+
14+
#rstrip() 清除字符串末尾的空白
15+
#lstrip() 清除字符串开头的空白
16+
#strip() 清除字符串开头和末尾的空白

old/cases/book_case02_列表.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
bicycles = ['terk','cannondale','redine','specialized'] #与C语言类似
2+
print(bicycles)
3+
print(bicycles[0].title())
4+
5+
print("bicycles[-1]:")
6+
print(bicycles[-1].title()) #当索引为-1时即访问最后一个元素
7+
print()
8+
9+
print("修改元素后:")
10+
bicycles[2] = 'redline' #修改元素
11+
print(bicycles)
12+
print()
13+
14+
print("bicycles.append('just_a_bike'):")
15+
bicycles.append('just_a_bike') #在列表末尾添加元素
16+
print(bicycles)
17+
print()
18+
19+
print("insert:")
20+
bicycles.insert(0,'other_bike') #在列表中插入元素(在n处添加空间,并将值储存在该位置)
21+
print(bicycles)
22+
print()
23+
24+
print("del:")
25+
del bicycles[0] #删除指定索引元素(后面元素自动前移)
26+
print(bicycles)
27+
print()
28+
29+
print("pop:")
30+
temp=bicycles.pop() #默认弹出最后一个元素,可加参数弹出指定元素
31+
print(bicycles)
32+
print(temp)
33+
print()
34+
35+
print("remove:") #根据元素的值删除指定元素
36+
bicycles.remove("redline")
37+
print(bicycles)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
num=int(input("请输入一个数字(1~7):"))
2+
3+
if num==1:
4+
print("星期一")
5+
elif num==2:
6+
print("星期二")
7+
elif num==3:
8+
print("星期三")
9+
elif num==4:
10+
print("星期四")
11+
elif num==5:
12+
print("星期五")
13+
elif num==6:
14+
print("星期六")
15+
elif num==7:
16+
print("星期日")
17+
else:
18+
print("非法输入")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
print("九九乘法表")
2+
i=1
3+
j=1
4+
5+
while i<=9:
6+
while j<=i:
7+
print("%d*%d=%d\t"%(j,i,i*j),end="")
8+
j+=1
9+
print()
10+
j=1
11+
i+=1
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#1.打印功能提示
2+
3+
print(35*"=")
4+
print(" 名字管理系统")
5+
print("1.添加一个新的名字")
6+
print("2.删除一个名字")
7+
print("3.修改一个名字")
8+
print("4.查询一个名字")
9+
print("5.退出")
10+
print(35*"=")
11+
12+
#2.获取用户输入
13+
names=[]
14+
15+
#3.根据用户的选择,执行相应功能
16+
while(True):
17+
num=int(input("请输入功能序号:"))
18+
if num==1:
19+
new_names=str(input("请输入名字:"))
20+
if new_names in names:
21+
print("该名字已存在!")
22+
else:
23+
names.append(new_names)
24+
print(names)
25+
elif num==2:
26+
delete_name=str(input("请输入要删除的名字:"))
27+
if delete_name in names:
28+
names.remove(delete_name)
29+
else:
30+
print("输入的姓名不存在")
31+
elif num==3:
32+
change_name=str(input("请输入要更改的名字:"))
33+
if change_name in names:
34+
n_name=str(input("请输入新名字:"))
35+
if(n_name in names):
36+
print("该名字已存在!")
37+
else:
38+
names[names.index(change_name)]=n_name
39+
else:
40+
print("该名字不存在!")
41+
elif num==4:
42+
find_name=str(input("请输入要查询的名字:"))
43+
if find_name in names:
44+
print("存在")
45+
else:
46+
print("不存在")
47+
elif num==5:
48+
break
49+
else:
50+
print("输入有误!")
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
cards = []
2+
while True:
3+
print(35*"=")
4+
print("名片管理系统")
5+
print("1.添加一个新的名片")
6+
print("2.删除一个名片")
7+
print("3.修改一个名片")
8+
print("4.查询一个名片")
9+
print("5.显示所有名片")
10+
print("6.退出")
11+
print(35*'=')
12+
13+
num=int(input("请输入功能序号:"))
14+
15+
if num == 1:
16+
new_name =input("请输入姓名:")
17+
new_email = input("请输入邮箱:")
18+
new_tel = input("请输入电话号码:")
19+
new_info = {"name":new_name,"email":new_email,"tel":new_tel}
20+
cards.append(new_info)
21+
22+
print(cards)#for test
23+
elif num==2:
24+
del_name =input("请输入姓名:")
25+
for temp in cards:
26+
if temp["name"]==del_name:
27+
break
28+
29+
30+
elif num==3:
31+
pass
32+
elif num==4:
33+
find_name=input("请输入姓名:")
34+
flag=0
35+
for temp in cards:
36+
if find_name == temp["name"]:
37+
print("姓名\t邮箱\t电话号码\t")
38+
print("%s\t%s\t%s\t"%(temp["name"],temp["email"],temp["tel"]))
39+
flag=1
40+
if flag==0:
41+
print("未找到%s"%find_name)
42+
elif num==5:
43+
print("姓名\t邮箱\t电话号码\t")
44+
for temp in cards:
45+
print("%s\t%s\t%s\t"%(temp["name"],temp["email"],temp["tel"]))
46+
elif num==6:
47+
break
48+
else:
49+
print("输入有误请重新输入!")

old/cases/video_case05_烤地瓜.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class SweetPotato:
2+
3+
def __init__(self):
4+
5+
self.cookedString = "生"
6+
self.cookedLevel = 0
7+
8+
def __str__(self):
9+
return "地瓜状态:%s(%d)"%(self.cookedString,self.cookedLevel)
10+
11+
def cook(self,cooktime):
12+
self.cookedLevel += cooktime
13+
14+
if self.cookedLevel>=0 and self.cookedLevel<3:
15+
self.cookedString = "生的"
16+
elif self.cookedLevel>=3 and self.cookedLevel<5:
17+
self.cookedString= "半生不熟"
18+
elif self.cookedLevel>=5 and self.cookedLevel<8:
19+
self.cookedString = "熟了"
20+
elif self.cookedLevel>=8:
21+
self.cookedString = "烤糊了"
22+
23+
24+
digua = SweetPotato()
25+
digua.cook(1)
26+
print(digua)
27+
digua.cook(1)
28+
print(digua)
29+
digua.cook(1)
30+
print(digua)
31+
digua.cook(1)
32+
print(digua)
33+
digua.cook(1)
34+
print(digua)
35+
digua.cook(1)
36+
print(digua)
37+
digua.cook(1)
38+
print(digua)
39+
digua.cook(1)
40+
print(digua)
41+
digua.cook(1)
42+
print(digua)
43+
digua.cook(1)
44+
print(digua)
45+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Home:
2+
def __init__(self,new_area,new_info,new_addr):
3+
self.area = new_area
4+
self.info = new_info
5+
self.addr = new_addr
6+
self.left_area = new_area
7+
def __str__(self):
8+
return "房子的面积是:%d,可用面积是%d,户型是:%s,地址是%s"%(self.area,self.left_area,self.info,self.addr)
9+
10+
def add_item(self,item):
11+
self.left_area -= item.area
12+
class Bed:
13+
def __init__(self,new_name,new_area):
14+
self.name = new_name
15+
self.area = new_area
16+
17+
def __str__(self):
18+
return "%s占用面积%d"%(self.name,self.area)
19+
20+
21+
fangzi = Home(180,"n室n厅",'xx市 xx xx xxx')
22+
print(fangzi)
23+
24+
bed1 = Bed("大床",4)
25+
print(bed1)
26+
27+
fangzi.add_item(bed1)
28+
print(fangzi)

old/cases/video_case07_4s店.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class CarStore(object):
2+
def __init__(self):
3+
self.factory = Factory()
4+
5+
def order(self,car_type):
6+
k = self.factory
7+
f = k.select_car_by_type(car_type)
8+
return f
9+
10+
class Factory(object):
11+
def select_car_by_type(self,car_type):
12+
if car_type == "suonata":
13+
return Suonata()
14+
elif car_type == "mingtu":
15+
return Mingtu()
16+
elif car_type == "ix25":
17+
return Ix35()
18+
19+
class Car(object):
20+
def move(self):
21+
print("moving...")
22+
def music(self):
23+
print("lalala...")
24+
def stop(self):
25+
print("stop")
26+
27+
class Suonata(Car):
28+
pass
29+
30+
class Mingtu(Car):
31+
pass
32+
33+
class Ix35(Car):
34+
pass
35+
36+
37+
car_store = CarStore()
38+
car = car_store.order("ix25")
39+
car.move()
40+
car.music()
41+
car.stop()
42+

old/python-01_基础/01-first.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hi")

old/python-01_基础/02-注释.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
print("hello")
2+
3+
#这里是单行注释
4+
5+
6+
7+
'''
8+
print("hello")
9+
print("hello")
10+
print("hello")
11+
这里是多行注释
12+
'''
13+
14+
"""
15+
16+
"""

old/python-01_基础/03-变量.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
score = 100
2+
high = 180
3+
4+
applePrice =3.5
5+
weight = 7.5
6+
7+
money = applePrice*weight
8+
9+
print(money)
10+
11+
message = "i do not know"
12+
print(message+"\n")
13+
14+
money = money+10
15+
print(money)
16+
17+
18+

old/python-01_基础/04-input.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
high=input("请输入你的身高:")
2+
print("身高为:"+high)
3+
4+
#在python2中使用raw_input

old/python-01_基础/05-print.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
age = 18
2+
print("age=%d"%age)
3+
4+
name="傻子"
5+
print("名字是:%s"%name)
6+
7+
print("age=%d,name=%s"%(age,name))
8+
9+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
print("请输入年龄:")
3+
age_s=input() #input()输入的值默认为字符串类型
4+
age=int(age_s) #类型转换
5+
#使用 str(*) 转换为字符串
6+
7+
#age=int(input())
8+
9+
if age>=18: #冒号不可少!
10+
print("?") #必须缩进
11+
if(int(input())>0):
12+
print("go go go!")
13+
else:
14+
print("bye!")
15+
#elif [条件]:
16+
else: #冒号不可少!
17+
print("!") #必须缩进
18+
19+
print("\n\n例子:车票")
20+
21+
ticket =1 #1有0无
22+
knifeLength=8 #cm
23+
24+
if ticket == 1:
25+
print("检测到车票,开始安检...")
26+
if(knifeLength<=10):
27+
print("通过安检,祝您乘坐愉快!")
28+
else:
29+
print("请在原地等待工作人员")
30+
else:
31+
print("车票无效")
32+

old/python-01_基础/07-关键字.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import keyword
2+
print(keyword.kwlist)

0 commit comments

Comments
 (0)