1
i need help
SajidVijayan3 (1)

How do I make a yes or no question using elif staments in python

You are viewing a single comment. View All
Answered by heyitsmarcus (280) [earned 5 cycles]
View Answer
1
heyitsmarcus (280)

@SajidVijayan3 I'm thinking that somehow upon you pasting that code, the indentation was lost. But, beyond that, even though it looks like you're checking for the correct yes and no response, capitalization is important in this instance. Me, as a user, would think to put Yes with a capital Y or No with a capital N because you told me to. But, in your code, you aren't checking for a capital Y or a capital N.

This is actually an easy fix. You want to change the case to be either uppercase or lowercase (no matter what the user puts in), and then check for that case. So, notice in the code below, I'm converting message_1 to uppercase with message_1.upper() and then checking that it's equal to YES. This way, if the user types in YeS it still counts as a yes response.

message_1 = " "
while message_1.upper() != 'YES':
  print('Are you at the base yet?") (Yes/No)')
  message_1 = input()
print("Alright nice")

while message_1.upper() != 'NO':
  print('Why are taking so long?") (Yes/No)')
  message_1 = input()

Now, when the user runs it, they can type Yes or No in any case and it will recognize it. This is important as you have to think about UX while developing, as well.