Logische OF in Python

Logische OF vereist dat tenminste aan één voorwaarde is voldaan. Zo'n voorwaarde kan worden geschreven met de operator or.

Stel we hebben twee variabelen:

pythontst1 = 10
tst2 = -5

Laten we een voorwaarde opstellen - als de variabele tst1 groter is dan 0 of de variabele tst2 groter is dan 0, dan wordt '+++' naar de console uitgevoerd:

pythonif tst1 > 0 or tst2 > 0:
  print('+++') # dit wordt uitgevoerd
else:
  print('---')
Задание 1

Gegeven de variabelen:

pythontst1 = -1
tst2 = 4

Controleer of variabele tst1 gelijk is aan of kleiner dan 1, en variabele tst2 groter is dan of gelijk aan 3.

Задание 2

Zonder de code uit te voeren, bepaal wat er in de console wordt uitgevoerd:

pythontst1 = -10;
tst2 = -10;

if tst1 >= 0 or tst2 >= 0:
  print('+++');
else:
  print('---');
}
Задание 3

Zonder de code uit te voeren, bepaal wat er in de console wordt uitgevoerd:

pythontst1 = 0;
tst2 = 0;

if tst1 >= 0 or tst2 >= 0:
  print('+++');
else:
  print('---');
Задание 4

Zonder de code uit te voeren, bepaal wat er in de console wordt uitgevoerd:

pythontst1 = 0;
tst2 = 5;

if tst1 >= 0 or tst2 >= 0:
  print('+++');
else:
  print('---');
Задание 5

Zonder de code uit te voeren, bepaal wat er in de console wordt uitgevoerd:

pythontst1 = 5;
tst2 = 5;

if tst1 >= 0 or tst2 >= 0:
  print('+++');
else:
  print('---');
Задание 6

Zonder de code uit te voeren, bepaal wat er in de console wordt uitgevoerd:

pythontst1 = -5;
tst2 = 15;

if tst1 >= 0 or tst1 >= 0:
  print('+++');
else:
  print('---');
Задание 7

Zonder de code uit te voeren, bepaal wat er in de console wordt uitgevoerd:

pythontst = 1;

if tst == 0 or tst == 1:
  print('+++');
else:
  print('---');
Задание 8

Zonder de code uit te voeren, bepaal wat er in de console wordt uitgevoerd:

pythontst = 2;

if tst == 0 or tst == 1:
  print('+++');
else:
  print('---');
Задание 9

Zonder de code uit te voeren, bepaal wat er in de console wordt uitgevoerd:

pythontst = 2;

if tst == 0 or tst == 1 or tst == 2:
  print('+++');
else:
  print('---');