0
'''
make a test to test how much you understand the code for the project

what to do


functions:
print() input()

'''

I'm new to Python. I'm wondering why this program gives me 'correct!' when I enter any other words but not 'A' or 'a'. I want this program to answer me 'correct only when I type 'A', or 'a'. I think I still fully don't understand what or operator does or something else I should understand. Please help me out with this.

print('do you wanna take the test?(yes/no):')
answer = input()
if answer == 'yes':
    print('Q1. What do you need to think of first when to make a program?')
    print('A. What program I make? B. Write code first.')
    print('Choose which one is correct(A/B):')
    while True:
        A1 = input()
        if A1 == 'A'or 'a':
            print('correct!')

        else:
            print('Try again.')
            continue
else:
    print('May your heart be your guiding key.')
Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
User9712
  • 65
  • 1
  • 2
  • 6

2 Answers2

0

The statement if A1 == 'A'or 'a' will be interpreted as if (A1 == 'A') or 'a' and since 'a' is always True(a non-zero value), the condition will always be True.

On the other hand, if you write the conditional statement as if A1 in ['A', 'a'], this will check if either A1=='A' or A1=='a'.

Satish Prakash Garg
  • 2,213
  • 2
  • 16
  • 25
0
A1=='A' or 'a' 

Check if A1='A' and then if 'a' is not None. Here the second check is obviously true, because the string holds the value 'a'

Therefore the condition that you need to use is

if A1 in ('A','a'):
    #statements to be executed if the if condition is satisfied.

That is, it will check if A1 holds any value given in the list ('A' ,'a')

Hope it helps!

Keerthana Prabhakaran
  • 3,766
  • 1
  • 13
  • 23