Question: Using python complete the functions in the provided script, function definitions are provided below: Please avoid using any Python facilities/capabilities we have yet to cover
Using python complete the functions in the provided script, function definitions are provided below:
Please avoid using any Python facilities/capabilities we have yet to cover in the course.
Please use expressive variable names.
# ALL FILES YOUR CODE CREATES NEED TO GO IN THE "MYFILES" FOLDER
# YOU ARE NOT TO ALTER ANY GIVEN FILE IN ANY WAY, OR ADD ANYTHING
# ANY FILE OR FOLDER TO ANY GIVEN FOLDER
# ASSUME THESE FOLDERS AND FILES EXIST FOR SUBMISSION
# NOTE: NONE OF THE SOLUTIONS FOR ASSIGNMENT CAN USE THE CSV MODULE
# NOTE: NONE OF THE SOLUTIONS FOR ASSIGNMENT CAN USE THE PANDAS MODULE
# TESTS ARE NOT PROVIDED THIS WEEK. PAY CLOSE ATTENTION TO
# THE PROMPTS, VISUALLY CHECK FILES YOU CREATE TO MAKE SURE
# THEY ARE IN THE CORRECT OUTPUT FOLDER AND CONTAIN THE TEXT YOU INTENDED TO WRITE.
compute_session_stats
- Open the files in the given input folder (e.g., it could be named the datafiles folder).
- read in the contents from each .txt file there.
- The contents of each text file is a bunch of numbers separated by commas...there are some newlines as well.
- Gather all of the numbers from each file and compute a mean and standard deviation for each one using statistics.mean() and statistics.stdev().
- Each float value you produce should have 2 significant digits after the decimal point.
- You'll also need to extract the participant ID number from each file name.
- Then create an output file in the myfiles folder called "stats.csv".
- On each line, print 3 comma separated values: the participant ID, that participant's mean, and that participant's stdev.
- The first line should be "PID,Mean,Stdev"
- Notice that there are no spaces between the values!
- If an invalid folder_path is given, return False, otherwise return True when 'stats.csv' has been successfully created.
E.g.,: assume these files and folder paths exists
PID,Mean,Stdev
109,392.75,229.56
103,409.84,232.79
100,403.04,225.67
collate_surveys
- The goal of collage_surveys() is similar to compute_session_stats().
- You are to read in the text files in the provided folder.(called surveyResponses)
- Each file in this folder will contain text, and be named similar to surverresp_01, ... surverresp_04. Wherein the number is the survey_number
- You are to create a single output file in the myfiles folder called "collated_surveys.csv".
- On each line of collated_surveys.csv should be a survey number (take it from the filename), the number of characters in the response, and then the response.
- The first line of collated_surveys.csv needs to be "survey_number,character_count,response"
- Response prints the text in the file and character count returns the total number of characters in that file.
- Notice that there are no spaces between the values!
- If an invalid foler_path is given, return False, otherwise return True when 'collated_surveys.csv' has been successfully created.
E.g.: assume these files and folder paths exists
survey_number,character_count,response
13,19, hurts walking speed
06,134, I would say I always try to be safe when using my phone while walking by not walking close to the street...
09,79, I feel that it affect my safety more because i am not concentrating on the road
Script:
compute_session_stats(folder_path: Path, file_extension: str = 'txt') -> bool:
print('***REPLACE*** This line with your code')
def collate_surveys(folder_path: Path, file_extension: str = 'txt') -> bool:
print('***REPLACE*** This line with your code')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
