0

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.

martineau
  • 119,623
  • 25
  • 170
  • 301
peter
  • 15
  • 5

1 Answers1

1

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'):
Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • thanks it worked but i have two questions ,1-i want to add the points of yes and no at the end of the survey so i need the user to write them as variables not strings that's why i didn't used quotations? – peter Nov 02 '17 at 00:13
  • 2- how can i make the program go back to the first if when the user write something wrong? i don't want it to only repeat the question but to go back to if condition . – peter Nov 02 '17 at 00:15
  • @peter 1) check separately: if the answer was a yes, add 1 to a counter, else don't add. 2) put everything inside a loop. – Óscar López Nov 02 '17 at 00:17
  • what loop? you mean for or while? – peter Nov 02 '17 at 00:23
  • Any loop you need to make it work :) probably a `while`. – Óscar López Nov 02 '17 at 00:25