Define and use functions
Problem 1: Playing with Lists
Run Python IDLE or WingIDE to create a new python file and save it under the name YOURNAME-Lab9.py Reaplce YOURNAME with you actual name.
You need to review our lecture slides and check this String Website
and List Website to learn the different operations of the string.
Function 1: main function
Call the function read_data defined below that will recieve no input but it will return two list of data (names, GPAs).
Call the function Print_Info defiend below and pass to it the 2 lists os student information.
Call the function Find_Average_GPA defiend below and pass to it the GPAs list that will print he average GPA of all the students
The main function will look like the following:
def main():
names,GPAs=read_data()
Print_Info(names,GPAs)
Find_Average_GPA(avgs)
Function 2: Read Data
Write a function called read_data that will define two list students_name and students_GPA and read 3 students information from the user (name, GPA) using a while loop and store the names
in the students_name list and the GPA in inside the students_GPA list.
Function 3: Print Info
Write a function called Print_Info that recieves 2 parameteres which represent 2 lists. and it returns back nothing.
The function print the contents of the 2 list as shown in the sample below.
Function 4: Find Average GPA
Write a function called Find_Average_GPA that recieves 1 parameter which is a list that represetns the students GPA. and it calculates and print the average of the students GPAs.
--- Run example ---
Make sure that your result looks like the following:
Input student #1 name: john
Input student #1 GPA: 50
Input student #2 name: scott
Input student #2 GPA: 60
Input student #3 name: ryan
Input student #3 GPA: 90
====================
Name GPA
john 50.0
scott 60.0
ryan 90.0
====================
Average = 66.66666666666667
====================
Problem 2: Make a copy of a txt file in python
write down the three different ways of reading a file in python and write it back to another file (make copy), we have three different solutions as shown below.
you need to write down this three different ways and understand them.
Click here to Install the example file.
Program Prolog
For every of the the problem above, provide your solution in a file with the comment and prolog provided explaining your information and the program details:
# supply program prolog
# Prolog
# Author: Mary Smith
# Email: Mary.Smith@uky.edu
# Section: 00
# Date: 8/31/16
'''
Purpose: ....
Preconditions: ....
Postconditions: ....
'''
Requirments:
1- for problem 1, You have to build four different functions (read_data(),Print_Info(),Find_Average_GPA()) also you need to have the main function.
2- Choose names for your variables that make sense, do not use short names consist of one letter. Use good, multi-character, meaningful identifiers (variables) names.
2- Your output should match the run examples provided with the problems above.
3- Document your work by putting comments at the top of your program, remember that comments in python are either:
starts with # in case the comment is one line only or ''' and ''' if the comment is taking more than one line.
4- At the top of your program, you should have a prolog (name, date, etc.)
5- For problem1, Save the solution for this lab in a file (List_your name.py).
6- For problem2, Save you work as sol_1.py, sol_2.py, and sol_3.py
When you are done with the lab, show your files to the instructor, sign the lab sheet, and then zip all the files in one and submit your work on CANVAS under lab9.