Very beginner in Python : If/else statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khaskhoa
    New Member
    • Sep 2021
    • 1

    Very beginner in Python : If/else statement

    Hello,
    I tried to make a simple program that interacts with the user and asks about his gender. However, I cannot seem to make it work past line 7. Could someone help me please ? Thanks a lot :)

    print ("Hello, nice to meet you. What's your name ?")
    name = input()
    print ("Hi, " + name)
    print ("That's a beautiful name.")
    print ("As for me, my name is Ali, I am a boy.")
    print ("Are you a boy as well ?")
    while True:
    prompt1 = input()
    if prompt1 == "yes":
    print("Hey bro")
    elif prompt1 =="no":
    print ("Hi sis")
    else:
    print ("Huh")
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Hello,
    I tried to make a simple program that interacts with the user and asks about his gender. However, I cannot seem to make it work past line 7. Could someone help me please ? Thanks a lot :)

    print ("Hello, nice to meet you. What's your name ?")
    name = input()
    print ("Hi, " + name)
    print ("That's a beautiful name.")
    print ("As for me, my name is Ali, I am a boy.")
    print ("Are you a boy as well ?")
    while True:
    prompt1 = input()
    if prompt1 == "yes":
    print("Hey bro")
    elif prompt1 =="no":
    print ("Hi sis")
    else:
    print ("Huh")
    I added the indentation and it seems to be working fine (python 3). What isn't working for you?
    Code:
    print ("Hello, nice to meet you. What's your name ?")
    name = input()
    print ("Hi, " + name)
    print ("That's a beautiful name.")
    print ("As for me, my name is Ali, I am a boy.")
    print ("Are you a boy as well ?")
    while True:
        prompt1 = input()
        if prompt1 == "yes":
            print("Hey bro")
        elif prompt1 =="no":
            print ("Hi sis")
        else:
            print ("Huh")

    Comment

    • bulieme
      New Member
      • Oct 2021
      • 2

      #3
      To reduce line.
      Also '\n' is a string break for python, you can called it 'enter'.

      Code:
      print ("Hello, nice to meet you. What's your name ?")
      name = input()
      print("Hi, " + name+ "\n That's a beautiful name.  \n As for me, my name is Ali, I am a boy.\n Are you a boy as well ?")
      while True:
          prompt1 = input()
          if prompt1 == "yes":
              print("Hey bro")
          elif prompt1 =="no":
              print ("Hi sis")
          else:
              print ("Huh")

      Comment

      Working...