0

I am learning python and trying to make a simple Q/A. It is my 1st day learning and been trying to find answers around the web, but I don't think I am asking the right questions... I am stuck on how to set an a question depending on the users answer.

This is my structure.

name = input(" What is your name? ")
if name == "xxx" or "yyy":
    print("Oh finally Hello " + name[0].upper() + name[1:].lower() + "!, Can't believe I finally met you, heard a lot about you! How are you doing chika!")
else:
    print("Hello " + name[0].upper() + name[1:].lower() + "how are you doing?")

Now I want to set an answer depending on what the user answers on "how are you doing?" How do I do so? and is there a way I can define + name[0].upper() + name[1:].lower() in like 1 word instead of typing it over and over again?

Thank you.

Rita
  • 37
  • 6
  • *"I want to set an answer depending on what the user answers on "how are you doing?" How do I do so?"* - what's wrong with the way you did it above (except the wrong `if` condition)? – Tomerikoo Jan 21 '21 at 14:37
  • Please see [Why does `a == b or c or d` always evaluate to True?](https://stackoverflow.com/questions/20002503/why-does-a-b-or-c-or-d-always-evaluate-to-true) regarding that `if` condition – Tomerikoo Jan 21 '21 at 14:38
  • Regarding your second question, there is a built-in for that: [`str.capitalize()`](https://docs.python.org/3/library/stdtypes.html#str.capitalize) - *"Return a copy of the string with its first character capitalized and the rest lowercased."* – Tomerikoo Jan 21 '21 at 14:39

1 Answers1

1

To make first letter uppercase, there is str.capitalize:

name = input(" What is your name? ").lower().capitalize() # make complete name lowercase first, then capitalize it
if name == "Xxx" or name == "Yyy":
    print("Oh finally Hello " + name + " !, Can't believe I finally met you, heard a lot about you !")
else:
    howdy = input("Hello " + name + " how are you doing?")
    if howdy = "good":
        print("Glad to hear you are doing good !")
    else:
        reason = input("Why are you not doing good ?")
        # and so on
TheEagle
  • 5,808
  • 3
  • 11
  • 39