0

the program should show me the right result. For example, if cor equals 'vermelho', print ('sua paleta equivale ao por do sol'), but isn't working.

class Bola:

    def escolha(self, cor):
        self.cor = cor

    def paleta(self):
        if self.cor == 'vermelho' or 'laranja' or 'lilas' or 'amarelo':
            print('sua paleta equivale ao por do sol')
        elif self.cor == 'azul' or 'branco':
             print('sua paleta equivale ao ceu')
        else:
             print('paleta nao definida')

bola = Bola()
bola.escolha('azul')
bola.paleta()
martineau
  • 119,623
  • 25
  • 170
  • 301
helciohjr
  • 15
  • 5
  • 1
    Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – Hari Krishnan May 28 '20 at 01:42

2 Answers2

0

The or operator doesn't work the way you're using it. Use:

        def paleta(self):
            if self.cor in {'vermelho', 'laranja', 'lilas', 'amarelo'}:
                print('sua paleta equivale ao por do sol')
            elif self.cor in {'azul', 'branco'}:
                 print('sua paleta equivale ao ceu')
            else:
                 print('paleta nao definida')

or tests whether either of two expressions is true; it doesn't create a set of expressions that you can test for equality against. For that you want to use a set (e.g. {'azul', 'branco'}) and the in operator.

Samwise
  • 68,105
  • 3
  • 30
  • 44
0

The statements as you have them are like this:

if a == 'b' or 'c':
    print('xyz')

This is asking: If a has a value of 'b' or if 'c' is True, print('xyz'). What you need to do is:

if a == 'b' or a == 'c':
    print('xyz')

This will (hopefully) give you the result you want. Another way to do it:

correct_responses = ['b', 'c', 'd']
if a in correct_responses:
    print('xyz')

Hope this helps!

InstaK0
  • 342
  • 3
  • 9