Aug-18-2019, 06:56 PM
Have you even tried that code? Do you understand why it's incorrect? Where are the two values you need stored? It really shouldn't be too hard.
hardest week yet: some guidence please
|
Aug-18-2019, 06:56 PM
Have you even tried that code? Do you understand why it's incorrect? Where are the two values you need stored? It really shouldn't be too hard.
Aug-18-2019, 07:25 PM
(This post was last modified: Aug-18-2019, 07:28 PM by raymond2688.)
(Aug-18-2019, 06:56 PM)ndc85430 Wrote: Have you even tried that code? Do you understand why it's incorrect? Where are the two values you need stored? It really shouldn't be too hard. I know its something simple and yes i ran the code this is the output: As I stated I do not believe that my values (maybe not the correct term) are going in my dictionary and I am certain it is not counting how many times each user attempts to log in. I know you say this should be simple, but please keep in mind I am in an introductory class 5 weeks ago I never wrote code before. I have struggled and spent countless hours on 1 assignment and this forum has helped me tremendously. and I thank everyone for thatupdated code so far intruder_log = {} with open("auth.log.1") as auth_log: for line in auth_log: if "Failed password" in line: start = line.find("invalid user") end = line.find(" from") name = line[start + 13:end] if name in intruder_log: intruder_log[name] += 1 else: intruder_log[name] = 1 for key in intruder_log: print("Attackers tried {1} times to log in as {0}".format(name, key))
Aug-18-2019, 11:13 PM
You want the key and value in the intruder_log, so both should be in your for statement (for key, value in....)
Now you have the value as well, which would be the _first_ parameter in your format to get it into the sentence logically. Do that, run, see what you get. Then you will know if you are counting and eliminating correctly.
Aug-22-2019, 09:12 AM
(Aug-18-2019, 11:13 PM)jefsummers Wrote: You want the key and value in the intruder_log, so both should be in your for statement (for key, value in....) Now you have the value as well, which would be the _first_ parameter in your format to get it into the sentence logically. Do that, run, see what you get. Then you will know if you are counting and eliminating correctly.english plz
Aug-22-2019, 02:50 PM
Not meaning to obfuscate, just a reminder that in the Homework forum that goal is to lead you to the answer rather than give you the answer. An "A Ha!" moment is much better for the learning process.
OK, in more detail. In line 16 he is looping through intruder_log, but by using for key in intruder_loghe is only getting the first value, where he really needs both (the name and the count) so for name, count in intruder_log:will pull both values. NOW you can print the results using the format method
Aug-22-2019, 05:23 PM
Actually, they both pull two values. It's just that the first one pulls both values into key, where the second one pulls them into two different variables. So key[0] == name and key[1] == count.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Calculating the number of day of the week | RbaPhoenix | 3 | 3,620 |
Mar-27-2020, 09:23 PM Last Post: Larz60+ |
|
week 1 python help - string formatting ? | raymond2688 | 20 | 10,702 |
Jul-09-2019, 08:10 PM Last Post: snippsat |
|
Trying to get the week number from a string of numbers | fad3r | 2 | 4,171 |
Apr-15-2018, 06:52 PM Last Post: ljmetzger |