What is wrong with these if and else statements?

peter

i am new with python and i am trying to make a survey but when i write this code things don't go well this is the first part of my very long survey:

#a program to test your adhd
yes=1
YES=1
Yes=1
no=0
NO=0
No=0
print("please honestly answer the following questions","\n"
"with \"yes\" or \"no\" ")
a=input("1. do you have difficulty getting organized ?")#q1
if a==yes or YES or Yes or no or NO or No:
b=input("2. When given a task, you usually procrastinate rather than doing it right away")#q2    
else:
print("wrong answer")
a=input("1. do you have difficulty getting organized ?")#q1

the idea of this is when the user write one of the true answers the program move to the next question. and if he wrote other things the program print wrong answer and repeat the question. but when tested with python shell and c.m.d it never consider the (else statement)

note that: i don't know many things in python (besides if and else statements) yet as i am at the very beginning on learning steps.

Óscar López

Notice that a is a string, and you'll have to test each condition separately (don't forget the quotes!), like this:

if a == 'yes' or a == 'YES' or a == 'Yes' or a == 'no' or a == 'NO' or a == 'No':

Or a simpler alternative:

if a.lower() in ('yes', 'no'):

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is wrong with my if else statements?

From Dev

what is wrong with this if else statment

From Dev

jQuery ignores if/then/else - what is wrong?

From Dev

What's wrong with this else if statement?

From Dev

What's wrong with this if/else/else if statement?

From Java

What is the effect of ordering if...else if statements by probability?

From Dev

What is called if 2 bools are true in if/else statements

From Dev

What is wrong with my understanding of switch statements?

From Dev

What is wrong with my understanding of switch statements?

From Dev

What's wrong with my IF/ELSE? "ELSE: Incorrect syntax near 'ELSE'."

From Dev

What's wrong with my if-else statement?

From Dev

What's wrong with the conditions in this IF-ELSE?

From Dev

If and if else statements working, but not else

From Dev

What alternatives to If-Else statements do batch files have?

From Dev

IF statements made redundant by ELSE statements

From Dev

if..else..in JSP. What's wrong with my code?

From Dev

python 2.7 chained conditions If Else not working. What's wrong?

From Dev

if..else..in JSP. What's wrong with my code?

From Dev

Using namespace in if / else statements

From Dev

Using multiple else if statements

From Dev

Angularjs if/else statements

From Java

IF-THEN-ELSE statements in postgresql

From Dev

Working with multiple if else statements

From Dev

Multiple if and else statements

From Dev

Return a function for IF ELSE IF statements

From Dev

Haskell if then else with "two statements"

From Dev

Bash script - if and else if statements

From Dev

If else statements with size of split

From Dev

Prolog without if and else statements

Related Related

HotTag

Archive