python作业不会做_【Python程序来求救了!又有两个不会、、、2.Writeaprogramthatreadsfromthekeyboardthreenamesfirst,middleandl...

Python 程序来求救了!又有两个不会、、、

2. Write a program that reads from the keyboard three names first, middle and last. Your program contains a main function that is responsible for prompting the user to enter three names all on one line and accept all three names as a single string. In your main function call another function (that you must also create) called initials and pass the string that you read. In the initials function you should parse through the name and convert the first name and middle name to initials complete with periods. Concatenate the two initials together along with the last name as a single string.

As an example, the name Jean Luc Picard would become J. L. Picard.

While you are at it, make sure that case of all of the names is correct. For example jeAn mARk kirk should become J. M. Kirk. Have your initials function return the new single string back to your main method for printing. Hint: Assume that the user always enters in three names. You will need to figure out where each name begins and ends. You do not need to loop this program. Work in very small steps. Separate the names out before you do anything else. Then worry about capturing the first initial, then worry about the upper/lower case. My output from two separate runs:

python question2.py

Please enter your name:Jean luc pICARD

Nice to meet you: J. L. Picard

python question2.py

Please enter your name:jeAn mARk KIRK

Nice to meet you: J. M. Kirk

3. Each line of data in a given file contains a person's employee id, their salary and their department (example below). Your employer wants to have answers to the following questions: 1) what is the average salary in the company, 2) what are the maximum and minimum salaries in the company 3) How many employees are there in each department.

To determine this, do the following. Read the data from the file one line at a time. Split the data into fields (separated by ':') and create two lists, one that contains all of the salaries, and one that contains all of the department information. Iterate through the salaries list (in a for loop) to determine the max, min and average salaries. Then iterate through the department list and determine the distribution of employees by department (Hint: There are only three departments: IT, Development and Administration).

You can do all of these tasks within a single main method. Catch any IOError exceptions that might occur and to be safe, catch any ValueError exceptions that might occur with respect to the salary data (in either case you may simply print an appropriate error message and terminate the program).

Test your program with provided file company.txt

python question6.py

Enter filename to process:company.txt

Salaries - Max: 124993.94 Min: 25015.53 Avg: 75041.0493683

Employees per dept - IT: 3398 Development: 3325 Administration: 3281

python question6.py

Enter a filename to process:somefilethatdoesnotexist.txt

A file IO error has occurred.

希望详细编一个。。。

作业帮用户2017-06-22举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值