|
| 1 | +""" /* |
| 2 | + * EJERCICIO: |
| 3 | + * - Crea ejemplos utilizando todos los tipos de operadores de tu lenguaje: |
| 4 | + * Aritméticos, lógicos, de comparación, asignación, identidad, pertenencia, bits... |
| 5 | + * (Ten en cuenta que cada lenguaje puede poseer unos diferentes) |
| 6 | + * - Utilizando las operaciones con operadores que tú quieras, crea ejemplos |
| 7 | + * que representen todos los tipos de estructuras de control que existan |
| 8 | + * en tu lenguaje: |
| 9 | + * Condicionales, iterativas, excepciones... |
| 10 | + * - Debes hacer print por consola del resultado de todos los ejemplos. |
| 11 | + * |
| 12 | + * DIFICULTAD EXTRA (opcional): |
| 13 | + * Crea un programa que imprima por consola todos los números comprendidos |
| 14 | + * entre 10 y 55 (incluidos), pares, y que no son ni el 16 ni múltiplos de 3. |
| 15 | + * |
| 16 | + * Seguro que al revisar detenidamente las posibilidades has descubierto algo nuevo. |
| 17 | + */ """ |
| 18 | + |
| 19 | +##Operadores aritmeticos |
| 20 | +print(f"Suma 100 + 50 :{100+50}") |
| 21 | +print(f"Resta 100 - 50 :{100-50}") |
| 22 | +print(f"Multiplicacion 100 * 50 :{100*50}") |
| 23 | +print(f"Division 100 / 50 :{100/50}") |
| 24 | +print(f"Modulo 100 % 50 :{100 % 50}") |
| 25 | +print(f"Potencia 2 ** 50 :{2**50}") |
| 26 | +print(f"Division entera 2 // 50 :{6**50}") |
| 27 | + |
| 28 | +## Operadores de comparacion |
| 29 | +print(f"Igual 6 == 6 :{6==6}") |
| 30 | +print(f"No igual 6 != :{6!=6}") |
| 31 | +print(f"Mayor 2 > 50 :{6>50}") |
| 32 | +print(f"Menor entera 2 < 50 :{6<50}") |
| 33 | +print(f"Menor o igual entera 2 <= 50 :{6<=50}") |
| 34 | +print(f"Mayor o igual entera 2 >= 50 :{6>=50}") |
| 35 | +print(f"Division entera 2 // 50 :{6**50}") |
| 36 | + |
| 37 | +##Operadores logicos |
| 38 | +print(f"AND True and True :{4+4 == 8 and 6 == 5+1}") |
| 39 | +print(f"OR True or False :{4+4 == 8 or 6 == 5}") |
| 40 | +print(f"NOT False :{not 6 == 9*3}") |
| 41 | + |
| 42 | +## Operadores de asignacion |
| 43 | +num = 4 |
| 44 | +print(num) |
| 45 | +num += 1 |
| 46 | +print(num) |
| 47 | +num -= 1 |
| 48 | +print(num) |
| 49 | +num *= 2 |
| 50 | +print(num) |
| 51 | +num /= 3 |
| 52 | +print(num) |
| 53 | +num %= 2 |
| 54 | +print(num) |
| 55 | +num **= 2 |
| 56 | +print(num) |
| 57 | +num //= 4 |
| 58 | +print(num) |
| 59 | + |
| 60 | +## Operadores de identidad |
| 61 | +my_var = 0.0 |
| 62 | +print(f"my_var is my_other_var {my_var is num}") |
| 63 | +print(f"my_var is not my_other_var {my_var is not num}") |
| 64 | + |
| 65 | +## Operadores de pertenencia |
| 66 | +print(f"'u' in 'lucas' = {'u' in 'lucas'}") |
| 67 | +print(f"'v' not in 'lucas' = {'u' not in 'lucas'}") |
| 68 | + |
| 69 | + |
| 70 | +## Operadores de bit |
| 71 | +a = 8 # 1000 |
| 72 | +b = 9 # 1001 |
| 73 | +print(f"AND : 8 & 9: {a & b}") |
| 74 | +print(f"OR : 8 | 9: {a | b}") |
| 75 | +print(f"XOR : 8 ^ 9: {a ^ b}") |
| 76 | +print(f"NOT : ~8: {~a}") |
| 77 | +print(f"RShift : 8 >> 2: {a >> 2}") |
| 78 | +print(f"LShift : 8 << 2: {a << 2}") |
| 79 | + |
| 80 | +## Estructuras de control |
| 81 | + |
| 82 | +## Condicionales |
| 83 | +var = "lucas" |
| 84 | +if var == "alberto": |
| 85 | + print("Condicional") |
| 86 | +elif var != "lucas": |
| 87 | + print("elif") |
| 88 | +else: |
| 89 | + print("else") |
| 90 | + |
| 91 | +##Iterativas |
| 92 | +for num in range(11): |
| 93 | + print(num) |
| 94 | + |
| 95 | +numer = 20 |
| 96 | +while numer > 0: |
| 97 | + print(numer) |
| 98 | + numer -= 1 |
| 99 | + |
| 100 | +## Excepciones |
| 101 | +try: |
| 102 | + 10 / 0 |
| 103 | +except: |
| 104 | + raise (ZeroDivisionError) |
| 105 | +finally: |
| 106 | + print("Finalizado exitosamente") |
| 107 | + |
| 108 | + |
| 109 | +## Extra |
| 110 | +for num in range(10, 56): |
| 111 | + if (not (num == 16 or num % 3 == 0)) and num % 2 == 0: |
| 112 | + print(num) |
0 commit comments