Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please answer BOTH PARTS of this step by step for PYTHON Create a new Python program in IDLE, and save it as lab12.py.

Can someone please answer BOTH PARTS of this step by step for PYTHON

image text in transcribedimage text in transcribed

Create a new Python program in IDLE, and save it as lab12.py. (Again, I recommend saving lab programs to a USB stick.) Part 1 Use Notepad++ to create a new text file called expr.txt. It should contain the following lines: 14+3+7+212+34+9+717+25+2+1 Save your expr.txt file in the same folder as your lab12.py file. First, define the function add_expr in your Python program. It should take an expression (like ' 2+3 ') as a parameter, which will be an expression of numbers added together like the examples above. This function should print the sum of the numbers in the parameter expression. Here are some tips for how to write it: - Use string replace to get rid of any spaces in the expression (replace all occurrences of " with ") - OR: Use string split with ' + ' as the delimeter to extract out each number. - Loop to add all numbers in the expression together, and print the sum after the end of the loop. You will need to use int() to tum each value in the list from string split into an integer. Then, write the main part of your Python program below the add_expr function. It should: - Open the expr.txt file, and read in the entire file as one string - Use string split with '!n' as the delimeter to break apart the file into a list of expressions - Loop through each expression in the list. For each one, call the odd_expr function (passing that expression) to print its sum. Your program should look like this when it runs (there is NO user input - all input is coming from the file): Expression: 14+3+7+21 Sum: 45 Expression: 2+3 Sum: 5 Expression: 4+9+7 Sum: 20 Expression: 17+25+2+1 Sum: 45 Part 2 Use Notepad++ to create another text file called scores.txt. It should contain the following lines: Mason Jones 86,73,72 Lucas Smith 77,87,92 Evelyn Lewis 94,88,89 Mia Young 61,75,68, Patrick Wilson 83,72,95 Save your scores.txt file in the same folder as your lab12.py file. as a parameter, which will be a row of data with the first name of the student, then the surname, followed by a sequence of scores. This function should print the full name of the student along with the average of their score numbers. Here are some tips for how to write it: - Use string split with ' 't ' (or' ', depending on how you separate the columns) as the delimeter to extract out each element. - Use split with ", as the delimiter on the third element of the returned list to breakup the score numbers. - Loop to add all numbers in the score list together. Afterwards, print the student's full name and then average after the end of the loop. You will need to use int[/ to turn each value in the list from string split into an integer. - Be sure to use corversion specifiers to round the average to two decimal places. The main part functions the same as in Part 1: - Open the scores.txt file, and read in the entire file as one string - Use string split with ' ' as the delimeter to break apart the file into a list of expressions - Loop through each row in the list. For each one, call the avg_scores function (passing that row) to print the student name and average. Your program should look like this when it runs (there is NO user input all input is coming from the file): Your program should look like this when it runs (there is NO user input -- all input is coming from the file): Student: Mason Jones Average Score: 77.00% Student: Lucas Smith Average Score: 85.33% Student: Evelyn Lewis Average Score: 90.33% Student: Mia Young Average Score: 68.00% Student: Patrick Wilson Average Score: 83.33% Here is an example screenshot of the program running in the IDLE shell: B. Pythan 1.7 in shell Hile fat Shell Debug Opticns Wiadow Hetp Fyge "help", "oopyright, "credits" or "license () " toe more infoumation. m>> asgmas: Ca/Users/ frida/Docuents/CIs 111 Eh/solution_to_lab12.py mmmm working with Files in Python Rast1: sxstestion114+3+7+21 3um: 45 Bxpression: 2+3 Sunt 5 sxpresision: 4+9+7 Suft 20 Bxpressiont 17+25+2+1 sum: 15 Part 2i student: Masce Jores hverage score: 77, 004 3tudent- tuces s-ith Rverage Score: 85.334 atudenti gvelyn Lewis Rverage scoze: 90.334 student: Mia Foung hverage seote: 69. sot gtudent: Patrick Wilson Rverage seese: 83.334 When you are finished, run your program in the Python shell and test it on the example above. If it looks exactly like the example when it runs, and if your program also includes the add expr function and the avg scores function, submit your solution to this assignment page

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

x-3+1, x23 Let f(x) = -*+3, * Answered: 1 week ago

Answered: 1 week ago