python 代写python作业、Directory代写python实验、python编程作业帮做 、代做python程序设计

日期:2018-09-23 04:19

2018/9/22 My_Phone_Directory

http://localhost:8888/nbconvert/html/Desktop/Python/My_Phone_Directory.ipynb?download=false 1/4

Case Study: Making a Phone Directory

1. We build a system where we ask the user to

a. enter record

b. Do a query

c. Load a file

d Save a file

e Exit

2. In our case enter a record means entering a name and a telephone number

3. So our system is simple. We just want a mechanism of storing names and phone numbers

4. Any given a name we want to pull out a phone number

1. There are many problems which have this format.

2. A menu with a list of possible actions that can be taken

3. A mechanism for retrieving data from a file and storing new data that you have

4. We have different routines for the different actions.

5. We have to be very careful on how we select data structures for the different activities

a. In practice the input and output routines have to be carefully designed so as to be idiot proof.

b. We do not want bad data to enter the system.

c. For example we will add some minimal features to ensure the telephone number is entered in a

format that we can use.

d. We may also want to provide some form of assistance to the query function. For example as the

person types a name the computer gives suggestions from the data base.

1. So we have a main program with perhaps 4 functions

2. We probably need a menu function as well

3. What data structures do we need.

2018/9/22 My_Phone_Directory

http://localhost:8888/nbconvert/html/Desktop/Python/My_Phone_Directory.ipynb?download=false 2/4

In [1]:

def main():

commands = [(1, 'Enter Records'), (2, 'Query'),

(3, 'Load File'), (4, 'Save'), (5, 'Exit')]

myInd = True

while myInd:

for i, s in commands:

print(i, s)

a = input()

if a == "":

break

a = int(a)

if a == 1:

pass

add_entry()

if a == 2:

pass

query()

if a == 3:

pass

loadfile()

if a == 4:

pass

savefile()

if a== 5:

myInd = False

phone={}

main()

1 Enter Records

2 Query

3 Load File

4 Save

5 Exit

5

2018/9/22 My_Phone_Directory

http://localhost:8888/nbconvert/html/Desktop/Python/My_Phone_Directory.ipynb?download=false 3/4

In [3]:

def add_entry():

a = 'Enter Name: '

a = input(a)

a = a.strip() # Just in case there are spaces at front or back

b = 'Enter Tel. Number'

b = input(b)

b = b.strip() # We want to get rid of leading and ending blank spaces

mylist = b.split() # create a list of numbers ( in case spaces are encountered in the mid

dle)

tel = ''.join(mylist) #concatenates the list

#Put into dictionary

phone[a] = tel

print(' The name ',a,' and tel: ', tel, ' has been added')

return

add_entry()

#ans,tel =add_entry()

#print(ans, tel)

In [4]:

def query():

a = 'Enter Name'

a = input(a)

a = a.strip()

b = phone.get(a)

if b ==None:

print("The name is not available")

else:

print('The Telephone Number of ', a, ' is ', b)

print('')

print('---------------------')

print('')

query()

Enter Name: Peter

Enter Tel. Number 216 368 3849

The name Peter and tel: 2163683849 has been added

Enter NamePeter

The Telephone Number of Peter is 2163683849

---------------------

2018/9/22 My_Phone_Directory

http://localhost:8888/nbconvert/html/Desktop/Python/My_Phone_Directory.ipynb?download=false 4/4

In [5]:

# Store each

def savefile():

a = input('Enter File Name to save to')

fn = open(a, 'w')

for k in phone: # recall k is the keyword ( name) and phone[k] is the phone number

fn.write(k+'\n')

fn.write(phone[k]+'\n')

fn.close()

savefile() # The file consists of alternate lines of names and phone numbers

In [6]:

def loadfile():

phone = {} # create a dictionary called phone

fname = input('Enter file to load: ')

try:

myfile = open(fname, 'r')

mylist = myfile.readlines() # reads all lines in the file into a list each line

#is an element in the list. It adds\n

for i in range(0, len(mylist), 2):

key_str = mylist[i].strip('\n')

val_str = mylist[i + 1].strip('\n')

phone[key_str] = val_str

print(fname, 'successfully loaded.')

myfile.close()

return phone

except:

print('I could not find the file')

return phone

phone = loadfile()

Enter File Name to save tomyfile

Enter file to load: myfile

myfile successfully loaded.

python实验报告代写_python 代写python作业、Directory代写python实验、python编程作业帮做 、代做python程序设计...相关推荐

  1. python的实验报告大一心理_Python程序设计实验报告: 实验六

    安徽工程大学 Python程序设计 实验报告 班级  物流192班   姓名吕晨学号3190505209  成就 日期    2020.5.4     指导先生修宇 [实验名称]实验六 函数 [实验目 ...

  2. python上机实验报告读取文件_Python程序设计实验报告:实验八 文件

    安徽工程大学 Python程序设计 实验报告 班级 物流192姓名陶俊 学号3190505235 成绩 日期 2020.6.3 指导老师修宇 实验八 文件 [实验目的] 掌握读写文本文件或 CSV 文 ...

  3. python上机实验报告读取文件_Python程序设计实验报告八 : 文件

    安徽工程大学 Python程序设计 实验报告 班级 物流192 姓名凌剑涛 学号 3190505233成绩 日期2020.6.3 指导老师 修宇 实验八 文件 [实验目的] 掌握读写文本文件或CSV文 ...

  4. python上机实验报告读取文件_Python程序设计实验八:文件

    安徽工程大学 Python程序设计实验报告 班级:物流192 姓名:李心悦 学号:3190505218成绩: 日期:2020.6.3 指导教师:修宇 [实验名称]实验八 文件 [实验目的] 掌握读写文 ...

  5. python的实验报告大一心理_python的期末实验报告

    青岛工学院 实验报告 <Python 语言基础>实验报告 实验室: 实验题目 年... python大作业实验报告.pptx_计算机软件及应用_IT/计算机_专业资料.... 温州大学瓯江 ...

  6. 计算机算法设计与分析 动态规划 实验报告,动态规划法解最长公共子序列(计算机算法设计与分析实验报告).doc...

    动态规划法解最长公共子序列(计算机算法设计与分析实验报告) 实报 告 实验名称:任课教师::姓 名:完成日期:二.主要实验内容及要求: 要求按动态规划法原理求解问题: 要求交互输入两个序列数据: 要求 ...

  7. c语言实验报告周信东,周信东主编最新版c语言程序设计基础实验一实验报告

    周信东主编最新版c语言程序设计基础实验一实验报告 (6页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 24.9 积分 --WORD格式--可编辑--专业资 ...

  8. python实验报告范文及模板_网络工程师-简历自我评价怎么写(范文)

    网络工程师简历模板-简历自我评价怎么写 [网盘下载]100+清新大气简历模板: https://zhuanlan.zhihu.com/p/115911695 https://zhuanlan.zhih ...

  9. python的for循环语句怎么写_python中的for循环语句怎么写

    python中的for循环语句怎么写? Python for 循环语句 Python for循环可以遍历任何序列的项目,如一个列表或者一个字符串. for循环的语法格式如下:for iterating ...

  10. python地址怎么写_python文件地址(文件路径)怎么写

    python文件地址(文件路径)怎么写 windows系统中输入文件目录的时候是''反斜杠符号,因为window 读取文件可以用\,如: os.chdir('D:\软件\NotePad++\Proje ...

最新文章

  1. python基础-------迭代器,生成器,协程函数
  2. linux--nfs 网络文件共享
  3. linux获取url中文内容_Chrome OS 似乎将在Linux 的方向上更进一步
  4. Flink JAR包上传和运行逻辑
  5. 操作系统原理:中断,异常,系统调用
  6. ITK:在傅立叶域中过滤图像
  7. 6个炫酷又好用的 Python 工具,个个都很奔放呀
  8. 查一个字段中字符集超过30的列_详细解读MySQL的30条军规
  9. Android5.0L因SystemUI ANR导致的黑屏问题分析
  10. 去哪儿-02-HeaderDev
  11. webService调用模式比较
  12. python验证身份证最后一位数字代表什么_身份证尾数带X的人,是有什么特殊身份吗?看完涨知识了...
  13. Java、JSP电子政务系统
  14. 学报格式和论文格式一样吗_求《浙江大学学报》的论文格式要求 - 论文投稿 - 小木虫 - 学术 科研 互动社区...
  15. 用友软件用友二次开发用友单据导入用友凭证导入工具用友EXCEL导入工具EXCEL导入凭证
  16. java成员变量是什么
  17. oppoa11android版本是什么,oppoa11x处理器是什么?oppoA11x配置介绍
  18. 走近Palantir
  19. jmeter---Throughput(吞吐量)系列
  20. 用EXCEL宏编写坐标转换

热门文章

  1. Intent.parseUri()详解
  2. 有赞多平台推广接入与测试
  3. python爬取qq音乐歌词风变编程_爬取QQ音乐歌词
  4. 美国车联网(V2X)发展现状与反思
  5. 火车票软件哪个好用_买火车票哪个软件好用 哪个软件买火车票便宜
  6. Chrome浏览器快捷键
  7. Eclipse创建maven工程后没有build path解决方案
  8. 微信 android应用签名生成工具,GitHub - feinoah/WeChatSignature: 改进版本的微信应用签名生成工具,再也不用输入包名了!...
  9. 全国电话区号->地址映射表
  10. 【复现】CNVD-2020-10487-Tomcat-Ajp-lfi