Question: Python programming 3.1 beginner codes/please no advanced codes to be used Attached Files: attacks.csv (412 B) Objectives: The purpose of this homework assignment is to

Python programming 3.1 beginner codes/please no advanced codes to be used

Attached Files: attacks.csv (412 B) Objectives: The purpose of this homework assignment is to demonstrate your ability to apply what you have learned about dictionaries and CSV files. Instructions: Attached is a CSV file that contains rows of data describing the attack information from a particular IP address. The first column is the IP address, the second the country of origin, the third the number of attack attempts and the fourth represents the number of unique user names used in the attacks. For example, IP address 222.234.0.57 is in the Republic of Korea and attempted to log in 599 times using 580 invalid user names. Apparently some of the user names were used more than once. Your objective is to open the file, read it line by line, split the data into individual variables and assign it to three different dictionaries. The key for each dictionary is the IP address. Each dictionary contains different values that can be associated with the key (IP). For example, use the IP to look up the coutry of origin in one dictionary, the number of attacks in another and the number of unique user names in the third dictionary. Provide a menu that allows the user to select what it is they would like to do. They can: Find the number of attacks associated with an IP address Find the country of origin for an IP Find the number of different invalid user names tried Quit For any of the choices (except Quit), the user enters the IP address. If the address does not match any in the data, simply display a message that there is no record of an attack attempt from that IP. Extra credit: Since the first line of the CSV file is a column heading, the first row of data is not valid. "IP" will be added as a key to each of the tables with the other column headings showing as values. No credit will be deducted for this behaviour. However, if you find a way to ignore the first line of data when you read the file, you'll be awarded up to 10 points extra credit, depending upon the quality of your solution. please give another code not the same one as shown below

dict1 = {} dict2 = {} dict3 = {} with open("input19.txt") as f: #Assuming input file is input19.txt for line in f: if line.split(',')[0] == "IP": continue; ip = line.split(',')[0] country = line.split(',')[1] num_attacks = line.split(',')[2] num_users = line.split(',')[3] dict1[ip] = country dict2[ip] = num_attacks dict3[ip] = num_users choice = 1 while choice != 4: print("1.Find the number of attacks") print("2.Find the country of origin") print("3.Find the number of invalid users") print("4.Quit") choice = int(input("Enter your choice:")) if choice == 1: inp = input("Enter IP:") if dict2.get(inp) != None: print("Number of attacks:",dict2.get(inp)) else: print("No record for attack attempt from ",inp) else: if choice == 2: inp = input("Enter IP:") if dict1.get(inp) != None: print("Country of origin: ",dict1.get(inp)) else: print("No record for attack attempt from ",inp) else: if choice == 3: inp = input("Enter IP:") if dict3.get(inp) != None: print("Number of invalid users:",dict3.get(inp)) else: print("No record for attack attempt from ",inp) print(" ")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!