This code I wrote for my study on if statements in Python doesn't seem to work properly since it asks the same question twice after the first one being asked.
Identity = input("Who are you? ")
if Identity == "Jane":
print("You must be John's sister.")
elif Identity != "John":
print("My database doesn't recognise you. Who are you I wonder...")
elif Identity == "John":
if input("What is your last name? ") != "Travolta":
print("False! John's name is Travolta and not " input("What is your last name? ") ".")
elif input("How old are you? ") == "Travolta":
if input("How old are you? ") != "20 yo":
print("False! John is 20 yo and not " input("How old are you? ") ".")
elif input("How old are you? ") == "20 yo":
print("You must in fact be John!")
CodePudding user response:
if input("What is your last name? ") != "Travolta":
print("False! John's name is Travolta and not " input("What is your last name? ") ".")
Here you aren't storing the value of the input and printing it. You are asking the person to input again "what is your last name?".
Do something like
last_name = input("What is your last name? ")
and use it instead of the input() in the if statement.
CodePudding user response:
can you be more explicit with: "since it asks the same question twice after the first one being asked.". Send a screenshot to see