Search code examples
pythonvariablesinput

How to save a user's input as a variable?


I am learning Python and trying to make a program that asks:

  1. Where are you from? if user responds "Buenos Aires" the program asks
  2. Should we kill em all?

That part is done. What I want to do next is make it so that if the user responds to 2 with "yes" the program responds with "Damn straight soldier." Best I can think of is that I should have the user's input from 2 saved as a variable and write something that says if that variable = yes then print("damn straight soldier"). But how do I designate the user input in response to 2 as a variable?

Current code:

user_location = input("where are you from?:")
if user_location == "Buenos Aires":
print(input("should we kill em all?:"))

Round 2:

user_location = input("where are you from?:")
Buenos_Aires = input("should we kill em all?:")
if user_location == "Buenos Aires":
    print(Buenos_Aires)
    if Buenos_Aires == "yes":
        print("damn straight soldier")

Round 3:

user_location = input("where are you from?:")
if user_location == "Buenos Aires":
    print(Buenos_Aires)

Buenos_Aires = input("should we kill em all?:")
if Buenos_Aires == "yes":
        print("damn straight soldier")

Round 4: (still getting "yes" as the end here)

user_location = input("where are you from?:")

if user_location == "Buenos Aires":
    kill_em_all = input("should we kill em all?:")

    if kill_em_all == "yes":
        print("Damn Straight Soldier")

Round 5 - Copy Paste Code I copy pasted code RMills says works for his system but is still giving me "yes" as the end.


Solution

  • What I'm proposing is a slight change to your round 3 code.

    user_location = input("where are you from?:")
    
    if user_location == "Buenos Aires":    
        kill_em_all = input("should we kill em all?:")
    
        if kill_em_all == "yes":
            print("damn straight soldier")
    

    This looks to follow your requirements above.

    Note that if they don't say they are from Buenos Aires, the program will end.

    enter image description here