Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A beginner code...
#1
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
Reply
#2
on line #6 you want to assign value returned from input() to name
And you don't need line#2
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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?
Reply
#4
(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")
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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
Reply
#6
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.
Reply
#7
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
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!!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner: Code not work when longer list raiviscoding 2 765 May-19-2023, 11:19 AM
Last Post: deanhystad
  Code not reading http link from .txt file (Beginner level) plarrip 3 2,353 Dec-17-2020, 11:33 PM
Last Post: bowlofred
  Beginner: I need help understanding few lines of a code. hop_090 1 1,642 Sep-07-2020, 04:02 PM
Last Post: Larz60+
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,682 Jun-18-2020, 04:59 PM
Last Post: QTPi
  [Beginner] Code is not producing desired result fakej171 2 2,380 Mar-21-2020, 10:26 AM
Last Post: buran
  what function should i use to tidy up my code (extreme beginner) scraig0117 4 2,255 Dec-16-2019, 04:03 PM
Last Post: scraig0117
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 2,367 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Beginner trying to code in python RA0211 1 1,816 Sep-26-2019, 11:10 AM
Last Post: emryscass
  Beginner Code bh3282 9 4,461 Mar-18-2019, 03:58 PM
Last Post: samsonite
  [Help] Beginner's code Owenix 3 2,705 Sep-15-2018, 08:03 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020