forked from midudev/curso-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_booleans.py
More file actions
56 lines (48 loc) · 1.73 KB
/
02_booleans.py
File metadata and controls
56 lines (48 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
###
# 02 - Booleanos
# Valores lógicos: True (verdadero) y False (falso).
# Fundamentales para el control de flujo y la lógica en programación.
###
from os import system
if system("clear") != 0: system("cls")
# Los booleanos representan valores de verdad: True o False.
print("\nValores booleanos básicos:")
print(True)
print(False)
# Operadores de comparación: devuelven un valor booleano.
print("\nOperadores de comparación:")
print("5 > 3:", 5 > 3) # True
print("5 < 3:", 5 < 3) # False
print("5 == 5:", 5 == 5) # True (igualdad)
print("5 != 3:", 5 != 3) # True (desigualdad)
print("5 >= 5:", 5 >= 5) # True (mayor o igual que)
print("5 <= 3:", 5 <= 3) # False (menor o igual que)
print("\nComparación de cadenas:")
print("'manzana' < 'pera':", "manzana" < "pera") # True
print("'Hola' == 'hola'", "Hola" == "hola") # False
# Operadores lógicos: and, or, not
print("\nOperadores lógicos:")
print("True and True:", True and True) # True
print("True and False:", True and False) # False
print("True or False:", True or False) # True
print("False or False:", False or False) # False
print("not True:", not True) # False
print("not False:", not False) # True
# Tablas de verdad (para referencia):
print("\nTablas de verdad:")
print("\nand:")
print("A B A and B")
print("True True ", True and True)
print("True False", True and False)
print("False True ", False and True)
print("False False", False and False)
print("\n or:")
print("A B A or B")
print("True True ", True or True)
print("True False", True or False)
print("False True ", False or True)
print("False False", False or False)
print("\n not:")
print("A not A")
print("True ", not True)
print("False", not False)