def dave_check(user_name):
if user_name == "Dave" or user_name == "angela_catlady_87":
return "Get off my computer Dave!"
# Enter a user name here, make sure to make it a string
user_name = 'scott'
print(dave_check(user_name))
Below is the correct code for the function for the exercise. I thought that after a “return” line in a function, the function “switches off” and lines under the return aren’t read by the program. How come the second conditional statement is read if it is after the return “Get off my computer Dave” line? Is it because the first conditional statement was not met and so the function doesn’t complete the first “return” and so continues reading the code? Any help is much appreciated
def dave_check(user_name):
if user_name == "Dave":
return "Get off my computer Dave!"
if user_name == "angela_catlady_87":
return "I know it is you Dave! Go away!"
Seems you answer your own question? The first if condition is false, so the return keyword is not reached. Only when a return keyword is reached, is data returned/handed back which signals that the function is done executing
Can’t I update the value of user_name by using += so to include other values of the same variable?
For example, can’t I write user_name += "angela_catlady_87" so it includes both Dave and angela_catlady_87?
You can’t, because then the string would become "Daveangela_catlady_87"
what you want would require working with lists, something that will taught later. Your way of thinking is certainly the right one That is a positive you should take from this
Yes you are not supposed to do that you cannot update the names of variables with += that’s only for numeric values
your meant to make something new for example
if user_name = “angela_catlady_87”
print(“Get off my computer angela”)
Hi, in some other languages such as Java Script, there are parentheses after “if”, so I tried doing that with python. I noticed adding parentheses around the boolean statement do not change the if statement’s output and doesn’t result in a syntax error. Why’s that? Is there a difference between with parentheses and without? Should I be using parentheses or not for if statements? Thanks.
user_name = "angela_catlady_87"
if (user_name == "angela_catlady_87"):
print("I know it is you, Dave! Go away!")
vs
user_name = "angela_catlady_87"
if user_name == "angela_catlady_87":
print("I know it is you, Dave! Go away!")
can someone help me with this; i want to make a user lock,i have made this code but its not working properly : (can someone modify this)
user = print (input ("tell user: "))
if user == "admin":
print("welcome")
if user != "admin":
print ("who are you?")
like when you type admin(in the terminal) this should say ‘welcome’.
when you type anything other than admin(in the terminal) it should say ‘who are you?’
please tell solution
I can’t seem to figure out why this code won’t work.
username = input('What is your username?')
if username == 'Dave':
print ("I know it's you, Dave!")
if username == 'John':
print ("Bogger off, John!")
It returns:
Output:
What is your username?Traceback (most recent call last):
File "script.py", line 1, in <module>
username = input('What is your username?')
EOFError: EOF when reading a line