Python not executing line of code

Hi!

I am new to Python and trying to practice if/else statements. Going OK, and the code gets executed, however, there is one block that does not work the way I want to, but I cannot figure out why. I want the player to choose a weapon, the options are a machete or a morningstar, but it won’t print the syntax after the if statement despite the chosen option is a machete.

If it makes any difference, I am trying nested if statements.

weapon_of_choice = input("You have an option to choose a weapon. machete or morningstar?")
if weapon_of_choice == "machete":
        print("Good choice! Your machete is named Rolf.")
else:
        print("Ahh you slayer! Your morningstar only listens to you, and its name is Rosa.")

The code executes fine, but it will print the “Ahh you slayer” regardless if the input is machete or Morningstar. I do not understand why.

I appreciate any help!!

I tried your code:

and worked as expected?

thank you for your help!! I realised that when answering the question I entered a space before “machete” which resulted in a false statement.

something I would recommend is to use the method strip() which is used to remove spaces at the start and end of a string. Also chaining the method lower() will help since you are checking to see if the string the user typed is ‘machete’ no matter if they typed it as MACHETE OR MaCHete.

so for example:

weapon_of_choice = input("You have an option to choose a weapon. machete or morningstar?") weapon = weapon_of_choice.strip().lower() if weapon == "machete": print("Good choice! Your machete is named Rolf.") else: print("Ahh you slayer! Your morningstar only listens to you, and its name is Rosa.")