Please Explain the Logic here. (python)

So here is the task from the study:
(link: https://www.codecademy.com/courses/learn-python-3/lessons/python-control-flow/exercises/if-statement)

1.

In script.py, there is an if statement. I wrote this because my coworker Dave kept using my computer without permission and he is a real doofus. If the user_name is Dave, it tells him to stay off my computer.

Enter a user name in the field for user_name and try running the program.

Solution:

user_name = “Dave”

if user_name == “Dave”:
print(“Get off my computer Dave!”)

OKAY EVERYTHING IS FINE

Part 2

Ugh! Dave got around my security and has been logging onto my computer using our coworker Angela’s user name, angela_catlady_87.

Set your user_name to be angela_catlady_87.

Update the program with a second if statement so it checks for Angela’s user name as well and prints

"I know it is you, Dave! Go away!"

in response. That’ll teach him!

Solution:

user_name = “Dave”

if user_name == “Dave”:
print(“Get off my computer Dave!”)

user_name = “angela_catlady_87”
if user_name == “angela_catlady_87”:
print(“I know it is you, Dave! Go away!”)

MY QUESTION:

We are redefining user_name here to “angela_catlady_87” so if Dave tries “Dave” instead he shouldn’t see the message.

Shouldn’t we add something like if user_name == “Dave” or “angela_catlady_87”
or assign the second variable like used_name_2 = “angela_catlady_87”
and code if user_name == “Dave” or “angela_catlady_87”
so this would really help the purpose?

I don’t get this part the variable is updated with a new one so the program should not recognize “Dave” isn’t it?

for second suggestion:
or assign the second variable like user_name_2 = “angela_catlady_87”
and code
if user_name == “Dave” or
if user_name_2 “angela_catlady_87”
this would be more accurrate I guess

Hi,
I think it’s just a short fix for that lesson to help you get used to the syntax of the if statement.
I believe, the later lessons will go through things like and/or, else, etc and clear things up.
They’ve probably split it up a fair bit because there’s quite a lot to understand and it can be fairly easy to get lost trying to do it all at once.

Hope that helps

1 Like