Hi everyone, first and foremost I am a completely beginner in coding, I am starting from scratch on my own. Is hard but I know that I can learn this because I love fix problems. Ok, here is my beginner issue:
This is a bar
People < 18 don´t pass
People >= 18 are allowed IF their name is not "Marco"
Hence, IF your name is Marco, Go home. IF your name is not Marco, Welcome.
So far I have this:
current_age = int(input("Your current age: "))
name = ""
if current_age <18:
print ("Sorry, bye")
if current_age >= 18:
input ("and your name?: ")
if name == "Marco":
print ("Go home")
else:
print ("Welcome")
It discriminate by age, but not by name. Everyone is passing. I have burnt my brain for two days and I give up. Please help me
on line #6 you want to assign value returned from input()
to name
And you don't need line#2
Hi, buran. So
current_age = int(input("Your current age: "))
if current_age <18:
print ("Sorry, bye")
if current_age >= 18:
input ("and your name?: ")
if name == "Marco":
print ("Go home")
else:
print ("Welcome")
I have erased line 2. How Can I assign value returned from input() to name?
(Jun-18-2020, 05:06 AM)TheDude Wrote: [ -> ]How Can I assign value returned from input() to name?
the same way you assign the value for
current_age
:-)
current_age = int(input("Your current age: "))
if current_age < 18:
print("Sorry, bye")
if current_age >= 18:
name = input("and your name?: ")
if name == "Marco":
print("Go home")
else:
print("Welcome")
Ok
current_age = int(input("Your current age: "))
name=input("and your name?: ")
if current_age <18:
print ("Sorry, bye")
if current_age >= 18:
input ("and your name?: ")
if name == "Marco":
print ("Go home")
else:
print ("Welcome")
but now it doesn´t discriminate by age :( and also ask the name twice
You are asking for name input in two places now, one is in the correct location the other is actually assigning a value.
carefully look through each stage of what your code is now doing.
(Jun-18-2020, 05:13 AM)TheDude Wrote: [ -> ]but now it doesn´t discriminate by age
That's not true - it just ask for name, before check the age, but if the age is less than 18 it ill print
sorry, buy
(Jun-18-2020, 05:13 AM)TheDude Wrote: [ -> ]and also ask the name twice
because you keep line #6.
if you want to check age before asking for name just replace current line 6 with line 2, as I show in my previous post
Ok guys, I am closer now.
current_age = int(input("Your current age: "))
name=input("and your name?: ")
if current_age <18:
print ("Sorry, bye")
if current_age >= 18:
name
if name == "Marco":
print ("Go home")
else:
print ("Welcome")
the only problem is when the user is under 18, it should be say "sorry,bye" at first, and not ask for the name. I know is in line 6 but can´t figure it out.
Ok, I get it!
current_age = int(input("Your current age: "))
if current_age <18:
print ("Sorry, bye")
if current_age >= 18:
name=input("and your name?: ")
if name == "Marco":
print ("Go home")
else:
print ("Welcome")
Thanks for the patience and the guidance. All the time was in front of me. I know is not easy for people like me, but I am gonna keep trying. Thanks!!!