0

I am new to python I am trying to code this, I am asking a question, hence the "Are you a mutant" and depending on if the user responds with a yes or no it should come up the respective output but it works only for yes but not for no. how do i make it work for the elif output?

print("Are you a mutant?")
answer = input()
if    'Yes':
    print("Your application to Xavier's School for Gifted Youngsters has been accepted")
elif 'No':
    print("Your application was not successful on this occassion")

`

3
  • 1
    Try doing if answer == 'yes' Commented Nov 24, 2016 at 18:38
  • @OmidCompSCI thanks it worked Commented Nov 24, 2016 at 18:48
  • No problem, if you believe this answered your question below, please accept it so others may use it as a reference to this question. Commented Nov 24, 2016 at 18:59

2 Answers 2

0

You need to compare the variable that stores the users input with the thing you are comparing it to. In this case using the ==. Below is revised code off your example:

print("Are you a mutant?")
answer = input()
if answer == 'Yes':
    print("Your application to Xavier's School for Gifted Youngsters has been accepted")
elif answer == 'No':
    print("Your application was not successful on this occassion")
Sign up to request clarification or add additional context in comments.

Comments

0

You have to write raw_input instead of input. 'Input' just takes the text value but 'raw_input'get the input as a string. If you are using python2, then follow the code below:

print("Are you a mutant?")
answer = raw_input("Yes/No: ")

if answer == "Yes":
    print("Your application to Xavier's School for Gifted Youngsters has been accepted")
elif answer == "No":
    print("Your application was not successful on this occasion")

In python3 raw_input() was renamed to input(). Then follow the code below:

print("Are you a mutant?")
answer = input("Yes/No: ")

if answer == "Yes":
    print("Your application to Xavier's School for Gifted Youngsters has been accepted")
elif answer == "No":
    print("Your application was not successful on this occasion")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.