#!sur/bin/env python
'''
Copyright (C)2012
@authored by tws
last modefied at 2012/12/2 23:52
'''
import pickle,os
data = []
filename = os.getcwd() + os.path.sep + 'data' #文件保存路徑
def main():
global data #存放數(shù)據(jù)的列表
data = load()
string = '''
(A)dd new
(D)ispaly
(R)emove
(S)how all
(L)ist
(Q)uit
'''
while True:
action = input(string)
if action in 'Aa':
add()
elif action in 'Dd':
Display()
elif action in 'Rr':
Remove()
elif action in 'Ss':
Show()
elif action in 'Ll':
List()
elif action in 'Qq':
save()
break
else:
print('error,please input correct instruction')
def add():
info = {}
name = input('Input name\n')
company = input('Input company\n')
state = input('Input State\n')
email = input('Input E-mail Address\n')
info['name'] = name
info['company'] = company
info['state'] = state
info['email'] = email
data.append(info)#添加一個(gè)人的信息到數(shù)據(jù)結(jié)構(gòu)
def Display():
msg = input('which person would want to know(name)?\n')
exist = False #是否存在此人
for item in data:
if item['name'] == msg:
printdata(item)
exist = True
if not exist:
print('no such person!')
def Remove():
msg = input('which person would want to delete(by name)?\n')
exist = False #是否存在此人
for index,item in enumerate(data):
if item['name'] == msg:
printdata(item)
exist = True
while True:
info = input('is this person?(Y/N)\n')
if info in "Yy":
del(data[index])
print('Delete Success!')
break
elif info in 'Nn':
break
else:
print('please input correct inseruction')
if not exist:
print('no such person!')
def Show():
for item in data:
printdata(item)
def List():#自己實(shí)現(xiàn)其他的功能
pass
def other():
pass
def save():
fp = open(filename,'wb') #存好數(shù)據(jù)
pickle.dump(data,fp)
def load():
try:
fp = open(filename,'rb')
return pickle.load(fp)
except:
return []
def printdata(item):
print('name:' + item['name'] + '||' + 'company:' + item['company'] + '||'
+ 'state:' + item['state'] + '||' + 'email' + item['email'] + '\n')
if __name__ == '__main__':
main()大神~太感謝了~我自己也寫出了一個(gè),還是要謝謝,能要個(gè)Q嗎O(∩_∩)O哈哈~ 923551233歡迎新朋友哦
求python大神,題目是write a program to keep track of conference attendees
求python大神,題目是write a program to keep track of conference attendees
for each attendee,your program should keep track of name,company,state,mail.it should allow user to do things :add a new attendee,display info on a attendee,delete an attendee ,list the name and mail of all attendees,and list the name and mail from a given state.the attendee should be stored in a file and loaded when the program starts.這個(gè)不用界面也可以嗎?思路是怎么樣的.因?yàn)槭浅鯇W(xué)者,所以希望能幫個(gè)忙
for each attendee,your program should keep track of name,company,state,mail.it should allow user to do things :add a new attendee,display info on a attendee,delete an attendee ,list the name and mail of all attendees,and list the name and mail from a given state.the attendee should be stored in a file and loaded when the program starts.這個(gè)不用界面也可以嗎?思路是怎么樣的.因?yàn)槭浅鯇W(xué)者,所以希望能幫個(gè)忙
其他人氣:906 ℃時(shí)間:2020-06-02 09:47:27
優(yōu)質(zhì)解答
我來(lái)回答
類似推薦
- 【Python】程序問題,求大神
- Write a program which asks the user for four numbers(Python)
- 3的平方-1的平方=8×1,5的平方-3的平方等于8×2,7的平方-5的平方=8×3,9的平方-7的平方=8×4,用代數(shù)式表示這個(gè)規(guī)律,并計(jì)算2001的平方-1999的平方的值.
- 一個(gè)兩位數(shù)的個(gè)位數(shù)與十位數(shù)之和為12,其中個(gè)位數(shù)字為a則這個(gè)兩位數(shù)是:
- 近代以來(lái)中國(guó)婚姻觀念的變化
- 古詩(shī)《過零丁洋》中,作者聯(lián)寫了個(gè)人和國(guó)家哪兩件大事
- absolutely
- I am reading an English story,[ ] my sister is watching tv.這里填什么連詞 為什么?
- 七年級(jí)所有古詩(shī)詞
- 二泉映月第五自然段仿寫
- 我們 把地球的什么叫做地軸
- 世界上兩大山脈地帶分布在哪里.
猜你喜歡
- 1第一個(gè)社會(huì)主義國(guó)家的建立有什么歷史意義?
- 2因式分解:(1) 12a²b(x-y)³-4ab(y-x)² (2) (a²-4a)²+(3a-12)²
- 3一筐蘋果6個(gè)一拿剩4,7個(gè)一拿剩5,8個(gè)一拿剩6這筐蘋果至少有幾個(gè)如果大約有500多個(gè)那么有幾個(gè)
- 4求小學(xué)語(yǔ)文《激動(dòng)人心的時(shí)刻》說課稿.及課件.
- 5用描述法表示下列集合:{3,9,27,81,…}
- 6求直線y=5x+3關(guān)于直線y=-x對(duì)稱的直線的函數(shù)解析式
- 7一架長(zhǎng)為十米的梯子AB斜靠在墻上 梯子的頂端距地面的垂直距離為8米 梯子下滑多少米 頂端下滑距離=底端下滑距離
- 8用無(wú)窮小定義證明:當(dāng)x趨向于3時(shí),f(x)=(x-3)/(x+1) 是無(wú)窮小 (用無(wú)窮小定義證明!)
- 9risk doing與risk to do
- 10新冷媒和氟里昂 這2種制冷劑有什么區(qū)別?哪個(gè)好?好在哪里
- 11為什么內(nèi)質(zhì)網(wǎng)的膜不能合成ATP?
- 12500千克加700千克是大于1噸還是小于或等于