Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your task is to write a program that processes the text file studentResponses.tx

ID: 3779231 • Letter: Y

Question

Your task is to write a program that processes the text file studentResponses.txt. The program should provide the user 5 choices for analyzing the contents of the text file. The choices are 1. Perform a keyword count from among the answers to question 3. Your program should prompt the user for the keyword 2. Calculate the average months of coding experience from among the survey responses. 3. Calculate average months of coding experience among all students who have a specific keyword in their answer to question 3. Your program should prompt the user for the keyword. If there are no responses among all students to question 3 with a specific keyword, the answer should be 0 (the program should NOT crash). 4. Calculate of students familiar with for loops 5. Quit (the program ends) Your program file must be named processUserData.py, and your program must Prompt the user for the name of the file to be processed Read the contents of the file only once (hint save the contents of the file into a list or dictionary) From among the survey responses, if the answer to the first survey question contains anything OTHER than an integer, the answer to that question should be treated as ifthe response was 0 (zero). If the response to the second question is anything OTHER than yes, the answer to that question should be treated as if the response was no continue to prompt the user ofthe program what analysis should be performed until the user types s, to signal quit. If the user specifies 1 through 4, that analysis should be performed. Nicely format percentage as well as decimal values to include 1or 2 decimal places. Contains a main method that has fewer than 20 lines of code (excluding comments). All custom method(s) have fewer than 20 lines of code (excluding comments) too

Explanation / Answer

def key( keyword , file1): #function for counting number of keywords
   count = 0#initializing count to 0
   for i in range(len(file1)):#travesing through list i which file contents are stored
       if keyword in file1[i]:#checking whether keyword is there are not in answer to question 3
       count = count + 1
   print(count)#printing answer
   return#returning

def exp ( file1 ):#function to calculate average coding experience of all people
count = 0
for i in range (len(file1)):#reading list of experiences
try:
count = count + float(file1[i])#checking it's a number and adding to count
except ValueError:
count = count
print(count/len(file1))#calculating average as count/number of people
return

def exp_key ( keyword , file1 , file3 ):#average coding experience of those with keyword in answer to third question
count = 0
number = 0
for i in range(len(file1)):#traversing list
if keyword in file3[i]:#checking for keyword
number = number + 1#updating number of people with keyword
try:
count = count + float(file1[i])#updating total experience
except ValueError:
count = count
print(count/number)#printing average experience of people with specific keyword
return

def for_loop( file2):#function to calculate percentage of people with knowledge in for loops
count = 0
for i in range(len(file2)):#traversing list with for loop knowledge information
if file2[i] == "yes":#if yes incrementing count by 1
count = count +1
print((count/len(file2))*100)#percentage = n_people with knowledge / total people * 100
print("Enter FileName:")
filename=input()
File1 = []
File2 = []
File3 = []
exit = 0
file = open(filename, "r")
for line in file:#reading input file into lists
temp = line.split('|')
File1.append(temp[0])
File2.append(temp[1])
File3.append(temp[2])
while (exit == 0) :#loop for taking inputs from user for tasks to be performed
a=input("1 for counting number of occurances of keyword in answer 3 2 for calculating avergae coding experience 3 for calculating average coding experience of people with some keyword appearing in their answers 4 for calculating % of students familiar with for loops 5 for quitting ")
if ( a == "5" ):
exit = 1
if ( a == "1" ):
keyword = input("enter keyword ")
key(keyword,File3)#function calls
if ( a == "2"):
exp ( File1)
if ( a == "3"):
keyword = input("enter keyword ")
exp_key(keyword , File1 , File3)
if( a == "4"):
for_loop(File2)