I wrote the code for these two programs and I keep getting name error for both. Don't understand what I am doing wring. Part B
I wrote the code for these two programs and I keep getting name error for both. Don't understand what I am doing wring.
Part B The dataset file in assets/grades.txt contains a line separated list of people with their grade in a class. Create a regex to generate a list of just those students who received a B in the course. In ! ): import re def grades(): with open ("assignments assignment1/assets/grades.txt, "r") as file: grades = file.read() # YOUR CODE HERE #()" in regex matches any words before "B" result = re.findall(..): B", grade) return result #return result print(grades) raise Not implementedError) En 1: assert len(grades()) - 16 Part C Consider the standard web log file in acetoogdata.xt. This file records the access a user makes when visiting a web page (like this one). Each one of the log has the following items: a host(e.g. 146.204.224.152') . a username (e.g, feest6811 note: sometimes the user name is missing in this case, use as the value for the username.) the time a request was made leg., 21/Jun 2019:15:45:24 -0700') DOO LE en The following cell failed: assert len(grades() == 16 NameError Traceback (most recent call last) in ----> 1 assert len(grades()) == 16 NameError: name 'grades' is not defined U The following cell failed: assert len(logs) == 979 one_item={'host': '146.284.224.152', 'user_name': 'feest6811', 'time': '21/Jun/2019:15:45:24 -0700', 'request': "POST /incentivize HTTP/1.1"} assert one_item in logs(), "Sorry, this item should be in the log results, check y our formating" NameError Traceback (most recent call last) in 1 assert len(logs() == 979 2 3 one_item={'host': '146.204.224.152', "user_name': 'feest6811', 5 time': '21/Jun/2019:15:45:24 - 0700', 4 NameError: name 'logs' is not defined Part C Consider the standard web log file in assets/logdata.txt. This file records the access a user makes when visiting a web page like this one!). Each line of the log has the following items: a host (0.9. 146.204.224.152') . a user name (0.g. Yoost0011' note: sometimes the user name is missing in this case, use as the value for the username.) the time a request was made (0.9., 21/Jun/2019.15:48:24 - 0700) . the post request type (0.9, "POST Ancentivize HTTP/1.1 note: not everything is a POSTI) Your task is to convert this into a list of dictionaries, where each dictionary looks like the following: example_dict = "host":"146.204.224.152", "user_name":"feest 6811", "time":"21/Jun/2019:15:45:24 -0700", "request": "POST /incentivize HTTP/1.1") In 1 1: import re def togs(): with open("assignments/assignment1/assets/Logdata.txt", "") as filer logdata file.read() * YOUR CODE MERE for in regex.finditer(logdata): data.append(m.groupdict()) return data regex = re.compile (?Pchost> (?:\d+\.){1,3}\d+) \s-\s! (Pauser_name> [\w\-]-) 715 Patie LAMASHALL "user_name":"feest6811", "time":"21/Jun/2019:15:45:24 -0700", "request":"POST /incentivize HTTP/1.1") In (): import re def logs(): with open("assignments/assignnent1/assets/logdata.txt", ") as file: togdata - tile.read() YOUR CODE HERE for m in regex.finditer(logdata): data.append(n.groupdict()) return data regex = re.compiled (?Pchost>(?:\d+1)(1,3)\d+)\s-\s+! (?Puser_name> I\w\-1*)?\5+" (P
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance