0

i put this code::

matirial = raw_input ('what is your favorite lesson')
    if matirial == 'maths' or 'math' or 'Maths' or 'Math' or 'رياضيات':
        print 'like me broo!!'

    elif matirial == 'french' or 'francais' or 'French' or 'Francais' or 'الفرنسية':
        print 'sorry dude I love English more then french'

    elif matirial == 'arabic' or 'arab' or 'العربية' or 'Arabic' or 'Arab':
        print 'this is my language'

    elif matirial == 'science' or 'Science' or 'bio' or 'Bio' or 'علوم':
        print 'I hate this matirial'

    elif matirial == 'history' or 'History' or 'histoire' or 'Histoire' or 'geographie' or 'Geographie' or 'his/geo' or 'His/Geo' or 'his\geo' or 'His\Geo' or 'جغرافيا' or 'تاريخ' or 'تربية' or 'social study' or 'Social study':
        print "i don't love to mimorize alot"

    elif matirial == 'sport' or 'Sport' or 'PE' or 'pe' or 'رياضة':
        print "and who don't love this matirial duuude"

    elif matirial == 'computer' or 'Computer' or 'ordinateur' or 'Ordinateur':
        print 'yaaaah of course this matirial is awesome'

    elif matirial == 'phisics' or 'Phisics' or 'phisique' or 'Phisisque' or 'فيزياء':
        print "it's awesome because she is like maths"

    elif matirial == 'chemistry' or 'Chemistry' or 'chimie' or 'Chimie' or 'كيمياء':    
        print "i don't love it oops"

    elif matirial == 'english' or 'English' or 'anglais' or 'Anglais' or 'انغليزية':
        print 'i love it more than my second language'

and it always give me the if of math..........why

4
Contributors
3
Replies
30
Views
6 Months
Discussion Span
Last Post by samson.dadson.3_1
0

Because of operator precedence, the first if is equivalent to

if ((matirial == 'maths') or ('math') or ('Maths') or ('Math') or ('رياضيات')):

The result of the or .. or .. or .. or is the first non false term, that is to say the string 'math' unless the user enters 'maths' in which case (material == 'maths') evaluates to True. In any cases, this if never fails because a non empty string is converted to True by the if statement.

What you want is

if material in ('maths', 'math', 'Maths', 'Math', 'رياضيات'):
0

Well you need to understand the if syntax. You probably mean to write if matirial == 'math' or matirial == 'Math' .... I won't talk about the use of in since you're not using that in your code, but I'll advice you read on that. It's much cleaner and efficient.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.