|
| 1 | +def Aritmeticos(): |
| 2 | + print("Operadores aritmeticos") |
| 3 | + a = 5 |
| 4 | + b = 2 |
| 5 | + |
| 6 | + print(f"Suma: {a} + {b} = {a + b}") |
| 7 | + print(f"Resta: {a} - {b} = {a - b}") |
| 8 | + print(f"Multiplicacion: {a} * {b} = {a * b}") |
| 9 | + print(f"Division: {a} / {b} = {a / b}") |
| 10 | + print(f"Modulo: {a} % {b} = {a % b}") |
| 11 | + print(f"Potencia: {a} ^ {b} = {a ** b}") |
| 12 | + |
| 13 | +def Logicos(): |
| 14 | + print("\nOperadores logicos") |
| 15 | + a = True |
| 16 | + b = False |
| 17 | + |
| 18 | + print(f"AND: {a} AND {b} = {a and b}") |
| 19 | + print(f"OR: {a} OR {b} = {a or b}") |
| 20 | + print(f"NOT: NOT {a} = {not a}") |
| 21 | + |
| 22 | +def Comparacion(): |
| 23 | + print("\nOperadores de comparacion") |
| 24 | + a = 5 |
| 25 | + b = 2 |
| 26 | + |
| 27 | + print(f"{a} > {b} = {a > b}") |
| 28 | + print(f"{a} >= {b} = {a >= b}") |
| 29 | + print(f"{a} < {b} = {a < b}") |
| 30 | + print(f"{a} <= {b} = {a <= b}") |
| 31 | + print(f"{a} == {b} = {a == b}") |
| 32 | + print(f"{a} != {b} = {a != b}") |
| 33 | + |
| 34 | +def Identidad(): |
| 35 | + print("\nOperadores de identidad") |
| 36 | + a = 1 |
| 37 | + b = 2 |
| 38 | + |
| 39 | + print(f"{a} is {b} = {a is b}") |
| 40 | + print(f"{a} is {b} = {a is b}") |
| 41 | + |
| 42 | +def Bits(): |
| 43 | + print("\nOperadores de Bits") |
| 44 | + a = 5 |
| 45 | + b = 3 |
| 46 | + |
| 47 | + print(f"AND: {a} & {b} = {a & b}") |
| 48 | + print(f"OR: {a} | {b} = {a | b}") |
| 49 | + print(f"XOR: {a} ^ {b} = {a ^ b}") |
| 50 | + print(f"Left shift: {a} << 3 = {a << 3}") |
| 51 | + print(f"Right shift: {a} >> 3 = {a >> 3}") |
| 52 | + print(f"NOT: !{a} = {~a}") |
| 53 | + |
| 54 | +def Pertenencia(): |
| 55 | + print("\nOperadores de Pertenencia") |
| 56 | + a = 4 |
| 57 | + lista = [1, 2, 3, 4 , 5] |
| 58 | + |
| 59 | + print("Lista:", *lista) |
| 60 | + print(f"{a} is in Lista = {a in lista}") |
| 61 | + print(f"{a} is not in Lista = {a not in lista}") |
| 62 | + |
| 63 | +def Condicionales(): |
| 64 | + a = 5 |
| 65 | + print(f"a = {a}") |
| 66 | + if a == 5: |
| 67 | + print("if: a == 1") |
| 68 | + |
| 69 | + if a != 5: |
| 70 | + print("if") |
| 71 | + else: |
| 72 | + print("else: a != 1") |
| 73 | + |
| 74 | + if a < 4: |
| 75 | + print("if") |
| 76 | + elif a > 4: |
| 77 | + print("elif: a > 4") |
| 78 | + else: |
| 79 | + print("else") |
| 80 | + |
| 81 | +def Iterativas(): |
| 82 | + for i in range(1,6): |
| 83 | + print("for") |
| 84 | + |
| 85 | + i = 5 |
| 86 | + while(i < 5): |
| 87 | + print("while") |
| 88 | + |
| 89 | +def Exceptions(): |
| 90 | + while True: |
| 91 | + try: |
| 92 | + x = int(input("Enter a number: ")) |
| 93 | + break |
| 94 | + except ValueError: |
| 95 | + print("Opps! That was no valid number. Try again...") |
| 96 | + |
| 97 | +def ExtraDificult(): |
| 98 | + for number in range(10, 56): |
| 99 | + if number % 2 == 0 and number != 16 and number % 3 != 0: |
| 100 | + print(number) |
| 101 | + |
| 102 | +def main(): |
| 103 | +# Operadores |
| 104 | + Aritmeticos() |
| 105 | + Logicos() |
| 106 | + Comparacion() |
| 107 | + Identidad() |
| 108 | + Bits () |
| 109 | + Pertenencia() |
| 110 | + |
| 111 | +# Operaciones |
| 112 | + Condicionales() |
| 113 | + Iterativas() |
| 114 | + Exceptions() |
| 115 | + |
| 116 | +# Dificultad Extra |
| 117 | + ExtraDificult() |
| 118 | +if __name__ == "__main__": |
| 119 | + main() |
0 commit comments