dic=,
『002』:}
#class fileaction():
@staticmethod
def writedate(dic):
f=open(「data.txt」,『w』,encoding=「utf-8」)
for k,v in dic.items():
for k1,v1 in v.items():
f.write( (k1+":"+str(v1)))
if k1==『num』:
f.write(』\n』)
else:
f.write(』,』)
f.close()
@staticmethod
def readdata( ):
f=open(『data.txt』,『r』,encoding=「utf-8」)
line=f.readline()
dzd={}
while len(line)>0:
items=line.strip().split(』,』)
zd={}
for item in items:
s=item.split(』:』)
if s[0]『age』:
zd[s[0]]=int(s[1])
else:
zd[s[0]] = s[1]
if s[0]『num』:
dzd[s[1]]=zd
line=f.readline()
print(dzd)
f.close()
fileaction.writedate(dic)
fileaction.readdata()
class people():
tax=0
definit(self,name,age,work,salary,energy=100):
self.name=name
self.age=age
self.work=work
self.salary=salary
self.__energy=energy
def working(self):
people.tax+=self.salary*0.2
self.__energy=self.__energy-30 if self.__energy>30 else 0
def eat(self,money):
self.__energy=self.__energy+10 if self.__energy<90 else 100
def sleep(self):
self.__energy=self.__energy+60 if self.__energy<40 else 100
def say(self):
print(self.name,self.age,self.work,self.salary)
def get_energy(self):
return self.__energy
class woman(people):
def shopping(self,money):
self.salary-=money
return self.salary# class man(people):
def say(self):
super().say()
print(「哈哈哈哈哈哈哈哈哈哈刀哈哈哈哈哈哈哈哈哈哈哈」)
m=man(「dd」,23,「運營總監」,1000000)
m.say()
w=woman(「ll」,21,「開發」,100000)
w.shopping(20000)
w.say()
class a():else:
zd={}
zd["name"]=input("請輸入姓名")
zd["age"]=int(input("請輸入年齡"))
zd["address"]=input("請輸入住址")
a[xh]=zd
print(a)
elif num==2:
xh = input("請輸入學號")
if xh not in a.keys():
print("查無此人")
continue
else:
print("要刪除的人是",a[xh])
del a[xh]
print(a)
elif num==3:
xh = input("請輸入學號")
if xh not in a.keys():
print("查無此人")
continue
else:
a[xh]["name"]=input("請輸入姓名")
a[xh]["age"]=int(input("請輸入年齡"))
a[xh]["address"]=input("請輸入位址")
print(a)
elif num==4:
xh = input("請輸入學號")
if xh not in a.keys():
print("查無此人")
continue
else:
print(a[xh])
else:
a=student.write()
print("您的輸入有誤,程式已退出")
break#exit(0)
count=0
definit(self,name):
self.name=name
a.count+=1
print(「建立了物件%s,共有%d個物件」%(self.name,a.count))
a=a(「牧塵」)def __del__(self): # 析構函式
a.count-=1
print("刪除了物件",self.name,"還剩%d個"%a.count)
b=a(「林動」)
del a
del b
class car():
defnew(cls, *args, **kwargs):
if not hasattr(car,「inst」):
car.inst=object.new(car)
return car.inst
definit(self,name,cid):
print(「666」)
self.name=name
self.cid=cid
a=car(「bmw」,「666」)
b=car(「bc」,「777」)
print(a is b)
print(a.name,a.cid)
print(b.name,b.cid)
學習筆記 笨方法學python
1.1 列表和字典 列表是有一組任意型別的值構成的有序列表,他由方括號構造而成 number list 1,2,3,4 mylist 1,a b 2,4 字典是由一組明值對構成的無序集合,由大括號構造而成 ages 可以通過以下方式訪問列表和字典中的元素 mylist 2 return a ages...
python學習筆記(12) 程式設計方法學
計算思維 邏輯思維 推演和演繹 實證思維 實驗和驗證,引力波 實驗 計算思維 設計和構造,計算機為代表,漢諾塔遞迴。計算思維特徵 抽象和自動化,抽象問題的計算過程,利用計算機自動化求解。計算生態的運用 程式設計的起點不是演算法而是系統,程式設計如同搭積木,利用計算生態為主要模式,程式設計的目標是快速...
笨方法學python
書結構非常簡單,其實就是 52 個習題而已。其中 26 個覆蓋了輸入輸出 變數 以及函式三個課題,另外 26 個覆蓋了一些比較高階的話題,如條件判斷 迴圈 類和物件 測試 以及專案的實現等。每一章節的格式基本都是一樣的,以 練習題開始,讀者照著說明 編寫 不允許複製貼上 執行並檢查結果,然後再做一下...