diff --git a/.gitignore b/.gitignore index 6ae071f8e9..60d5f850c6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ env/ .gitignore .venv - # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 8b869bd719..0000000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -python 3.8.10 diff --git a/_sources/lectures/TWP05/TWP05_16.rst b/_sources/lectures/TWP05/TWP05_16.rst index ec207f3b74..06936f0e84 100644 --- a/_sources/lectures/TWP05/TWP05_16.rst +++ b/_sources/lectures/TWP05/TWP05_16.rst @@ -49,11 +49,3 @@ Utilice el intérprete de modo interactivo aquí abajo para solucionar los sigui “La vida es como andar en bicicleta. Para mantener el equilibrio, debes seguir moviéndote”. - Einstein -.. poll:: TWP05 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? - - diff --git a/_sources/lectures/TWP05/TWP05_16_en.rst b/_sources/lectures/TWP05/TWP05_16_en.rst index c7a996910a..0a902c8ad5 100644 --- a/_sources/lectures/TWP05/TWP05_16_en.rst +++ b/_sources/lectures/TWP05/TWP05_16_en.rst @@ -45,12 +45,4 @@ Use the interactive interpreter below to solve the following exercises. :align: center :alt: -"Life is like riding a bicycle. To keep your balance, you must keep moving". - Einstein - - -.. poll:: TWP05E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? +"Life is like riding a bicycle. To keep your balance, you must keep moving". - Einstein \ No newline at end of file diff --git a/_sources/lectures/TWP10/TWP10_7.rst b/_sources/lectures/TWP10/TWP10_7.rst index 4a14c05ce2..9030c2c6d3 100644 --- a/_sources/lectures/TWP10/TWP10_7.rst +++ b/_sources/lectures/TWP10/TWP10_7.rst @@ -76,11 +76,4 @@ Lista de Ejercicios “again” :align: center :alt: -“La vida es como andar en bicicleta. Para mantener el equilibrio, debes seguir moviéndote”. - Einstein - -.. poll:: TWP10 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? \ No newline at end of file +“La vida es como andar en bicicleta. Para mantener el equilibrio, debes seguir moviéndote”. - Einstein \ No newline at end of file diff --git a/_sources/lectures/TWP10/TWP10_7_en.rst b/_sources/lectures/TWP10/TWP10_7_en.rst index c9764d0376..039a44e110 100644 --- a/_sources/lectures/TWP10/TWP10_7_en.rst +++ b/_sources/lectures/TWP10/TWP10_7_en.rst @@ -79,10 +79,3 @@ Exercise List “again” :alt: “Life is like riding a bicycle. To keep balance, you must keep moving”. - Einstein - -.. poll:: TWP10E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? diff --git a/_sources/lectures/TWP15/TWP15_3.rst b/_sources/lectures/TWP15/TWP15_3.rst index 02df53250b..fc80272b6c 100644 --- a/_sources/lectures/TWP15/TWP15_3.rst +++ b/_sources/lectures/TWP15/TWP15_3.rst @@ -4,7 +4,7 @@ Contadores + Ahora imprima de 1 a un número ingresado por el usuario .. activecode:: ac_l15_3a - + :nocodelens: :stdin: fin = int(input("Ingrese el último número: ")) @@ -16,7 +16,7 @@ Contadores + Imprima números pares entre 0 y un número dado por el usuario usando ``if`` .. activecode:: ac_l15_3b - + :nocodelens: :stdin: fin = int(input("Ingrese el último número: ")) diff --git a/_sources/lectures/TWP15/TWP15_6.rst b/_sources/lectures/TWP15/TWP15_6.rst index 4b4cbf0cc4..0173209792 100644 --- a/_sources/lectures/TWP15/TWP15_6.rst +++ b/_sources/lectures/TWP15/TWP15_6.rst @@ -27,10 +27,3 @@ Repeticiones anidadas “La vida es como andar en bicicleta. Para mantener el equilibrio, debes seguir moviéndote”. - Einstein - -.. poll:: TWP15 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? \ No newline at end of file diff --git a/_sources/lectures/TWP15/TWP15_6_en.rst b/_sources/lectures/TWP15/TWP15_6_en.rst index dc86e78992..13ea358ffc 100644 --- a/_sources/lectures/TWP15/TWP15_6_en.rst +++ b/_sources/lectures/TWP15/TWP15_6_en.rst @@ -24,11 +24,4 @@ Nested loops :align: center :alt: -"Life is like riding a bicycle. To keep your balance, you must keep moving" - Einstein - -.. poll:: TWP15E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? +"Life is like riding a bicycle. To keep your balance, you must keep moving" - Einstein \ No newline at end of file diff --git a/_sources/lectures/TWP17/TWP17_5.rst b/_sources/lectures/TWP17/TWP17_5.rst index f1d98c747a..ebabbeba89 100644 --- a/_sources/lectures/TWP17/TWP17_5.rst +++ b/_sources/lectures/TWP17/TWP17_5.rst @@ -8,10 +8,3 @@ Lista de Ejercícios “again” :alt: “La vida es como andar en bicicleta. Para mantener el equilibrio, debes seguir moviéndote”. - Einstein - -.. poll:: TWP17 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? \ No newline at end of file diff --git a/_sources/lectures/TWP17/TWP17_5_en.rst b/_sources/lectures/TWP17/TWP17_5_en.rst index 67295cdd72..384eabb599 100644 --- a/_sources/lectures/TWP17/TWP17_5_en.rst +++ b/_sources/lectures/TWP17/TWP17_5_en.rst @@ -7,11 +7,4 @@ Exercise List "again" :align: center :alt: -"Life is like riding a bicycle. To keep your balance, you must keep moving." - Einstein - -.. poll:: TWP17E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? +"Life is like riding a bicycle. To keep your balance, you must keep moving." - Einstein \ No newline at end of file diff --git a/_sources/lectures/TWP18/TWP18_7.rst b/_sources/lectures/TWP18/TWP18_7.rst index 100f61ab97..d95860c7b5 100644 --- a/_sources/lectures/TWP18/TWP18_7.rst +++ b/_sources/lectures/TWP18/TWP18_7.rst @@ -40,10 +40,3 @@ Programación en pareja :width: 18.201cm :align: center :alt: - -.. poll:: TWP18 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? \ No newline at end of file diff --git a/_sources/lectures/TWP18/TWP18_7_en.rst b/_sources/lectures/TWP18/TWP18_7_en.rst index 7f581b10e7..d0cec891a8 100644 --- a/_sources/lectures/TWP18/TWP18_7_en.rst +++ b/_sources/lectures/TWP18/TWP18_7_en.rst @@ -40,10 +40,3 @@ Pair programming :width: 18.201cm :align: center :alt: - -.. poll:: TWP18E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? \ No newline at end of file diff --git a/_sources/lectures/TWP20/TWP20_5.rst b/_sources/lectures/TWP20/TWP20_5.rst index dcb625eb59..a87544f58b 100644 --- a/_sources/lectures/TWP20/TWP20_5.rst +++ b/_sources/lectures/TWP20/TWP20_5.rst @@ -9,10 +9,3 @@ Lista de ejercicios "again" :alt: “La vida es como andar en bicicleta. Para mantener el equilibrio, debes seguir moviéndote”. - Einstein - -.. poll:: TWP20 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP20/TWP20_5_en.rst b/_sources/lectures/TWP20/TWP20_5_en.rst index 33d5e05725..a524c50a79 100644 --- a/_sources/lectures/TWP20/TWP20_5_en.rst +++ b/_sources/lectures/TWP20/TWP20_5_en.rst @@ -8,11 +8,4 @@ Exercise List "again" :align: center :alt: -"Life is like riding a bicycle. To keep your balance, you must keep moving." - Einstein - -.. poll:: TWP20E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? +"Life is like riding a bicycle. To keep your balance, you must keep moving." - Einstein \ No newline at end of file diff --git a/_sources/lectures/TWP23/TWP23_6.rst b/_sources/lectures/TWP23/TWP23_6.rst index fe137b3342..2b7f8ae6f9 100644 --- a/_sources/lectures/TWP23/TWP23_6.rst +++ b/_sources/lectures/TWP23/TWP23_6.rst @@ -45,10 +45,3 @@ “La vida es como andar en bicicleta. Para mantener el equilibrio, debes seguir moviéndote”. - Einstein - -.. poll:: TWP23 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP23/TWP23_6_en.rst b/_sources/lectures/TWP23/TWP23_6_en.rst index 2ccf28fe7c..067f08aada 100644 --- a/_sources/lectures/TWP23/TWP23_6_en.rst +++ b/_sources/lectures/TWP23/TWP23_6_en.rst @@ -44,11 +44,4 @@ Last Exercise :alt: -“Life is like riding a bicycle. To keep your balance, you must keep moving.” - Einstein - -.. poll:: TWP23E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? +“Life is like riding a bicycle. To keep your balance, you must keep moving.” - Einstein \ No newline at end of file diff --git a/_sources/lectures/TWP25/TWP25_5.rst b/_sources/lectures/TWP25/TWP25_5.rst index 6ab6cfe08f..4a6d2d593d 100644 --- a/_sources/lectures/TWP25/TWP25_5.rst +++ b/_sources/lectures/TWP25/TWP25_5.rst @@ -49,10 +49,3 @@ Múltiple herencia y ¿Qué objeto es? print(isinstance(wlan0, Ethernet)) print(isinstance(eth0, PCI)) print(isinstance(eth0, USB)) - -.. poll:: TWP25 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP25/TWP25_5_en.rst b/_sources/lectures/TWP25/TWP25_5_en.rst index ccef093e00..3fc828749f 100644 --- a/_sources/lectures/TWP25/TWP25_5_en.rst +++ b/_sources/lectures/TWP25/TWP25_5_en.rst @@ -48,11 +48,4 @@ Multiple Inheritance and What Object is It? print(isinstance(wlan0, Ethernet)) print(isinstance(eth0, PCI)) - print(isinstance(eth0, USB)) - -.. poll:: TWP25E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? + print(isinstance(eth0, USB)) \ No newline at end of file diff --git a/_sources/lectures/TWP30/TWP30_5.rst b/_sources/lectures/TWP30/TWP30_5.rst index 9899c61f49..ede30af30b 100644 --- a/_sources/lectures/TWP30/TWP30_5.rst +++ b/_sources/lectures/TWP30/TWP30_5.rst @@ -9,24 +9,47 @@ Repeticiones .. activecode:: ac_l30_5 - :nocodelens: - :stdin: - - import time - print('¡Bienvenido!') - chute = 0 - while chute != 42: - g = input('Ingrese un numero: ') - chute = int(g) - if chute == 42: - print('¡Ganaste!') + :language: python3 + :python3_interpreter: brython + + from browser import document as doc + from browser import html + from browser import timer + + print("¡Bienvenido!") + numero = 0 + + doc <= html.DIV(id="div_juego") + + # Creamos el botón para jugar + doc["div_juego"] <= html.BUTTON("Jugar", id="btn_jugar") + + # Definimos lo que hará el boton cuando sea apretado + def adivinar(): + + global numero + numero = int(input("Adivine el número: ")) + if numero == 42: + print("¡Ganaste!") else: - if chute > 42: - print('Alto') + if numero > 42: + print("Alto") else: - print('Bajo') - time.sleep(1) - print('Fin del juego!') + print("Bajo") + + if numero != 42: + # Si el número no se adivinó, se repite la función después de + # 3 segundos + timer.set_timeout(adivinar, 3000) + + + def empezar(ev): + adivinar() + + # Cuando el botón sea apretado, llamará a la función empezar, + # que a su vez llamará a adivinar. + doc["btn_jugar"].bind("click", empezar) + .. image:: ../img/TWP15_007.png :height: 14.804cm diff --git a/_sources/lectures/TWP30/TWP30_6.rst b/_sources/lectures/TWP30/TWP30_6.rst index 64ff339e84..610a68ab29 100644 --- a/_sources/lectures/TWP30/TWP30_6.rst +++ b/_sources/lectures/TWP30/TWP30_6.rst @@ -3,27 +3,44 @@ Sortear el número a adivinar .. activecode:: ac_l30_6 - :nocodelens: - :stdin: + :language: python3 + :python3_interpreter: brython + from browser import document as doc + from browser import html + from browser import timer from random import randint - import time - - print('¡Bienvenido!') - sorteado = randint(1,100) - chute = 0 - while chute != sorteado: - g = input('Ingrese un numero: ') - chute = int(g) - if chute == sorteado: - print('¡Ganaste!') - else: - if chute > sorteado: - print('Alto') + + print("¡Bienvenido!") + azar = randint(1, 100) + numero = 0 + + doc <= html.DIV(id="div_juego_2") + + # Creamos una caja de texto donde ingresar el número que queramos + doc["div_juego_2"] <= html.INPUT(id="inp_adivinar", placeholder="Adivine el número", type="number") + # Creamos el botón para adivinar + doc["div_juego_2"] <= html.BUTTON("Enviar adivinanza", id="btn_adivinar") + html.BR() + + def confirmar_adivinanza(e): + global numero + numero = int(doc["inp_adivinar"].value) + + if numero == azar: + print("¡Ganaste!") + print("¡Fin del juego!") + # Si el número es adivinado, el botón desaparece y el juego + # termina + doc["btn_adivinar"].style.display = "none" else: - print('Bajo') - time.sleep(1) - print('Fin del juego!') + if numero > azar: + print("Alto") + else: + print("Bajo") + + # Al apretar el botón, invoca a la función confirmar_adivinanza + doc["btn_adivinar"].bind("click", confirmar_adivinanza) + ¡Ahora sí! ---------- diff --git a/_sources/lectures/TWP30/TWP30_7.rst b/_sources/lectures/TWP30/TWP30_7.rst index 7a6709a4ab..1b20186d96 100644 --- a/_sources/lectures/TWP30/TWP30_7.rst +++ b/_sources/lectures/TWP30/TWP30_7.rst @@ -1,7 +1,7 @@ Herramientas de Python ====================== -+ Hello ++ Condiciones: ``if``, ``elif``, ``else`` + Ciclo: ``while`` + Operador de asignación: ``=`` + Operador de igualdad: ``==`` @@ -29,10 +29,3 @@ Ahora solo faltan tus ejercicios “La vida es como andar en bicicleta. Para mantener el equilibrio, debes seguir moviéndote ”. - Einstein - -.. poll:: TWP30 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP30/TWP30_7_en.rst b/_sources/lectures/TWP30/TWP30_7_en.rst index c68122089f..19d3ff09ed 100644 --- a/_sources/lectures/TWP30/TWP30_7_en.rst +++ b/_sources/lectures/TWP30/TWP30_7_en.rst @@ -28,11 +28,4 @@ Now all that's left are your exercises
-"Life is like riding a bicycle. To keep your balance, you must keep moving." - Einstein - -.. poll:: TWP30E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? +"Life is like riding a bicycle. To keep your balance, you must keep moving." - Einstein \ No newline at end of file diff --git a/_sources/lectures/TWP33/TWP33_9.rst b/_sources/lectures/TWP33/TWP33_9.rst index 8f508c611a..7b28a21f36 100644 --- a/_sources/lectures/TWP33/TWP33_9.rst +++ b/_sources/lectures/TWP33/TWP33_9.rst @@ -66,10 +66,3 @@ Herramientas de Python + El método ``text.find()`` busca una subcadena. + ``float()`` convierte algo a un punto flotante. + Bibliotecas: ``urllib.request`` y ``time``. - -.. poll:: TWP33 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP33/TWP33_9_en.rst b/_sources/lectures/TWP33/TWP33_9_en.rst index ff11d8f452..95df7617c5 100644 --- a/_sources/lectures/TWP33/TWP33_9_en.rst +++ b/_sources/lectures/TWP33/TWP33_9_en.rst @@ -65,11 +65,4 @@ Python Tools + ``text[4:9]`` accesses from the fifth to the ninth character. + The method ``text.find()`` searches for a substring. + ``float()`` converts something to a floating point number. -+ Libraries: ``urllib.request`` and ``time``. - -.. poll:: TWP33E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? ++ Libraries: ``urllib.request`` and ``time``. \ No newline at end of file diff --git a/_sources/lectures/TWP35/TWP35_4.rst b/_sources/lectures/TWP35/TWP35_4.rst index 645cea9d6c..167273b61e 100644 --- a/_sources/lectures/TWP35/TWP35_4.rst +++ b/_sources/lectures/TWP35/TWP35_4.rst @@ -30,10 +30,3 @@ JSON texto = urllib.request.urlopen(url).read() data = json.loads(texto) print(data["value"]["joke"]) - -.. poll:: TWP35 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP35/TWP35_4_en.rst b/_sources/lectures/TWP35/TWP35_4_en.rst index a5ff917415..196dffbdd2 100644 --- a/_sources/lectures/TWP35/TWP35_4_en.rst +++ b/_sources/lectures/TWP35/TWP35_4_en.rst @@ -27,11 +27,4 @@ JSON url = "http://api.icndb.com/jokes/random?limitTo=[nerdy]" text = urllib.request.urlopen(url).read() data = json.loads(text) - print(data["value"]["joke"]) - -.. poll:: TWP35E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? + print(data["value"]["joke"]) \ No newline at end of file diff --git a/_sources/lectures/TWP37/TWP37_6.rst b/_sources/lectures/TWP37/TWP37_6.rst index e7ba937bac..99b27cf551 100644 --- a/_sources/lectures/TWP37/TWP37_6.rst +++ b/_sources/lectures/TWP37/TWP37_6.rst @@ -100,14 +100,3 @@ Usando y ordenando un diccionario for participante in sorted(puntuaciones, reverse=True): print(f"{puntuaciones[participante]} obtuvo un puntaje de {participante:.2f}") - - -.. poll:: TWP37 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? - - - diff --git a/_sources/lectures/TWP37/TWP37_6_en.rst b/_sources/lectures/TWP37/TWP37_6_en.rst index 469592e8bf..0684729d2e 100644 --- a/_sources/lectures/TWP37/TWP37_6_en.rst +++ b/_sources/lectures/TWP37/TWP37_6_en.rst @@ -99,12 +99,4 @@ Using and sorting a dictionary file.close() for participant in sorted(scores, reverse=True): - print(f"{scores[participant]} obtained a score of {participant:.2f}") - - -.. poll:: TWP37E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? + print(f"{scores[participant]} obtained a score of {participant:.2f}") \ No newline at end of file diff --git a/_sources/lectures/TWP38/TWP38_4.rst b/_sources/lectures/TWP38/TWP38_4.rst index 8a9ff71001..8d3cc42ff9 100644 --- a/_sources/lectures/TWP38/TWP38_4.rst +++ b/_sources/lectures/TWP38/TWP38_4.rst @@ -48,11 +48,3 @@ Recuerde + Python es un lenguaje interpretado de alto nivel + El intérprete de Python convierte los comandos instrucción por instrucción a lenguaje máquina - - -.. poll:: TWP38 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP38/TWP38_4_en.rst b/_sources/lectures/TWP38/TWP38_4_en.rst index 63004c4fc5..958a508885 100644 --- a/_sources/lectures/TWP38/TWP38_4_en.rst +++ b/_sources/lectures/TWP38/TWP38_4_en.rst @@ -44,11 +44,4 @@ Remember + Programming languages have a formal syntax. + Computers only understand machine language. + Python is a high-level interpreted language. -+ The Python interpreter converts instructions command by command into machine language. - -.. poll:: TWP38E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? ++ The Python interpreter converts instructions command by command into machine language. \ No newline at end of file diff --git a/_sources/lectures/TWP40/TWP40_12.rst b/_sources/lectures/TWP40/TWP40_12.rst index e7b79acae4..a1dd11bd3b 100644 --- a/_sources/lectures/TWP40/TWP40_12.rst +++ b/_sources/lectures/TWP40/TWP40_12.rst @@ -20,21 +20,3 @@ Conversión de grados usando C C = 5.0 * (F - 32.0) / 9.0; printf("Celsius: %2.1f\n", C); } - -Conversión de grados usando Python ----------------------------------- - -.. code-block:: python - - F = float(input("Farenheit: ")) - C = 5.0 * (F - 32.0) // 9.0 - print("Celsius: %2.1f" % C) - -.. poll:: TWP40 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? - - diff --git a/_sources/lectures/TWP40/TWP40_12_en.rst b/_sources/lectures/TWP40/TWP40_12_en.rst index 448a2e1f04..9492980de5 100644 --- a/_sources/lectures/TWP40/TWP40_12_en.rst +++ b/_sources/lectures/TWP40/TWP40_12_en.rst @@ -19,11 +19,4 @@ Converting degrees using C scanf("%f", &F); C = 5.0 * (F - 32.0) / 9.0; printf("Celsius: %2.1f\n", C); - } - -.. poll:: TWP40E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? + } \ No newline at end of file diff --git a/_sources/lectures/TWP42/TWP42_3.rst b/_sources/lectures/TWP42/TWP42_3.rst index 18262300cb..b9a0749a1a 100644 --- a/_sources/lectures/TWP42/TWP42_3.rst +++ b/_sources/lectures/TWP42/TWP42_3.rst @@ -337,12 +337,4 @@ Agrupación de datos print() # cerrar el cursor - cursor.close() - - -.. poll:: TWP42 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? + cursor.close() \ No newline at end of file diff --git a/_sources/lectures/TWP42/TWP42_3_en.rst b/_sources/lectures/TWP42/TWP42_3_en.rst index 4a263911bd..864aacf44b 100644 --- a/_sources/lectures/TWP42/TWP42_3_en.rst +++ b/_sources/lectures/TWP42/TWP42_3_en.rst @@ -334,11 +334,4 @@ Grouping of data print() # close the cursor - cursor.close() - -.. poll:: TWP42E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? + cursor.close() \ No newline at end of file diff --git a/_sources/lectures/TWP45/TWP45_2.rst b/_sources/lectures/TWP45/TWP45_2.rst index f06701a342..d9b99bc945 100644 --- a/_sources/lectures/TWP45/TWP45_2.rst +++ b/_sources/lectures/TWP45/TWP45_2.rst @@ -17,7 +17,7 @@ En este ejercicio vamos a acceder a Reddit para obetener datos como los de la si import json # La url de Reddit a la que accederemos - url = "https://cors.bridged.cc/http://www.reddit.com/r/Python/.json" + url = "https://api.reddit.com/r/Python/.json" resp = urllib.request.urlopen(url).read() # La respuesta se da en formato json, se debe transformar a diff --git a/_sources/lectures/TWP45/TWP45_2_en.rst b/_sources/lectures/TWP45/TWP45_2_en.rst index ce13cce510..c44099b934 100644 --- a/_sources/lectures/TWP45/TWP45_2_en.rst +++ b/_sources/lectures/TWP45/TWP45_2_en.rst @@ -17,7 +17,7 @@ In this exercise we are going to access Reddit to obtain data like the one in th import json # The Reddit URL we'll access - url = "https://cors.bridged.cc/http://www.reddit.com/r/Python/.json" + url = "https://api.reddit.com/r/Python/.json" resp = urllib.request.urlopen(url).read() # The response is in JSON format, it needs to be transformed diff --git a/_sources/lectures/TWP45/TWP45_3.rst b/_sources/lectures/TWP45/TWP45_3.rst index 24660a01d6..ce1924a1e2 100644 --- a/_sources/lectures/TWP45/TWP45_3.rst +++ b/_sources/lectures/TWP45/TWP45_3.rst @@ -13,7 +13,8 @@ La documentación de la API de `TasteDive `_. .. activecode:: ac_l45_3a :nocodelens: - :language: python + :language: python3 + :python3_interpreter: brython En este caso, utilizaremos la librería ``requests`` para hacer la solicitud a la API. La url base es ``"https://tastedive.com/api/similar"``. A esta url se le va a pasar un parámetro ``q`` con el @@ -21,26 +22,29 @@ La documentación de la API de `TasteDive `_. Note que después de la url base se escribe un ``?`` para indicar que siguen los parámetros. ~~~~ - import requests + import urllib.request + import urllib.parse import json api_url = "https://tastedive.com/api/similar" - proxy = "https://cors.bridged.cc/" - # Los parámetros que se le pasaran a la url los escribimos dentro de un diccionario - parametros = {"q": "ariana grande"} + # Los parámetros que se pasarán a la url se escriben dentro de un diccionario. + parámetros = {"q": "ariana+grande"} + + #Codificamos los parámetros + parámetros = urllib.parse.urlencode(parámetros) - # Solicitamos a la api los datos - respuesta = requests.get(proxy + api_url, params=parametros) + # Solicitamos los datos de la api + respuesta = urllib.request.urlopen(api_url + '?' + parámetros) - # Ahora imprimimos la url - print(respuesta.url) - print() + # Leemos la respuesta + datos = respuesta.leer() - # Transformamos los datos de formato json a Python - datos = json.loads(respuesta.text) + # Analizamos los datos JSON + json_data = json.loads(datos) - print(datos) + # Ahora imprimimos los datos + print(json.dumps(json_data, indent=4)) En el ejemplo anterior pudo apreciar que la API regresa un texto, que si lo pasamos por ``json.loads`` @@ -48,6 +52,7 @@ se transforma a un diccionario de Python. Sin embargo, no es del todo legible. E ``json.dumps``. .. activecode:: ac_l45_3b + :nocodelens: :language: python3 :python3_interpreter: brython @@ -62,11 +67,11 @@ se transforma a un diccionario de Python. Sin embargo, no es del todo legible. E import json api_url = "https://tastedive.com/api/similar?" - proxy = "https://cors.bridged.cc/" + # La siguiente línea es para los parámetros de la url. parametros = urllib.parse.urlencode({"q": "coldplay"}) - solicitud = urllib.request.urlopen(proxy + api_url + parametros) + solicitud = urllib.request.urlopen(api_url + '?' + parametros) datos = json.loads(solicitud.read()) # Imprimimos los datos de forma legible para un usuario @@ -111,7 +116,7 @@ El siguiente ejercicio viene con calificación automática. import json api_url = "https://tastedive.com/api/similar" - proxy = "https://cors.bridged.cc/" + # Agregue los parámetros parametros = {} @@ -144,8 +149,8 @@ El siguiente ejercicio viene con calificación automática. def testOne(self): self.assertEqual( solicitud_url, - "https://cors.bridged.cc/https://tastedive.com/api/similar?q=Coco&limit=5&info=1", - "Probando que la url sea: https://cors.bridged.cc/https://tastedive.com/api/similar?q=Coco&limit=5&info=1", + "https://tastedive.com/api/similar?q=Coco&limit=5&info=1", + "Probando que la url sea: https://tastedive.com/api/similar?q=Coco&limit=5&info=1", ) self.assertEqual(resultados, 5, "Probando que resultados esté asignado correctamente.") self.assertEqual(len(peliculas_similares), 5, "Probando que peliculas_similares sean: 5") diff --git a/_sources/lectures/TWP45/TWP45_3_en.rst b/_sources/lectures/TWP45/TWP45_3_en.rst index 6b0fdded10..4051607271 100644 --- a/_sources/lectures/TWP45/TWP45_3_en.rst +++ b/_sources/lectures/TWP45/TWP45_3_en.rst @@ -12,7 +12,8 @@ The documentation for the `TasteDive API `_. .. activecode:: ac_l45_3a_en :nocodelens: - :language: python + :language: python3 + :python3_interpreter: brython In this case, we will use the ``requests`` library to make the API request. The base url is ``"https://tastedive.com/api/similar"``. To this url, a parameter ``q`` with the @@ -20,26 +21,29 @@ The documentation for the `TasteDive API `_. Note that after the base url, a ``?`` is written to indicate that the parameters follow. ~~~~ - import requests + import urllib.request + import urllib.parse import json api_url = "https://tastedive.com/api/similar" - proxy = "https://cors.bridged.cc/" # The parameters that will be passed to the url are written inside a dictionary - parameters = {"q": "ariana grande"} + parameters = {"q": "ariana+grande"} + + # We encode the parameters + params = urllib.parse.urlencode(parameters) # We request the data from the api - response = requests.get(proxy + api_url, params=parameters) + response = urllib.request.urlopen(api_url + '?' + params) - # Now we print the url - print(response.url) - print() + # We read the response + data = response.read() - # We transform the json-formatted data to Python data - data = json.loads(response.text) + # We parse the JSON data + json_data = json.loads(data) - print(data) + # Now we print the data + print(json.dumps(json_data, indent=4)) In the previous example, you could see that the API returns text, which if passed through ``json.loads`` @@ -47,6 +51,7 @@ transforms into a Python dictionary. However, it is not entirely readable. This ``json.dumps``. .. activecode:: ac_l45_3b_en + :nocodelens: :language: python3 :python3_interpreter: brython @@ -60,11 +65,11 @@ transforms into a Python dictionary. However, it is not entirely readable. This import json api_url = "https://tastedive.com/api/similar?" - proxy = "https://cors.bridged.cc/" + # The following line is for the url parameters parameters = urllib.parse.urlencode({"q": "coldplay"}) - request = urllib.request.urlopen(proxy + api_url + parameters) + request = urllib.request.urlopen(api_url + '?' + parameters) data = json.loads(request.read()) # We print the data in a user-readable format @@ -107,7 +112,6 @@ The following exercise comes with automatic grading. import json api_url = "https://tastedive.com/api/similar" - proxy = "https://cors.bridged.cc/" # Add the parameters parameters = {} @@ -140,8 +144,8 @@ The following exercise comes with automatic grading. def testOne(self): self.assertEqual( request_url, - "https://cors.bridged.cc/https://tastedive.com/api/similar?q=Coco&limit=5&info=1", - "Testing that the url is: https://cors.bridged.cc/https://tastedive.com/api/similar?q=Coco&limit=5&info=1", + "https://tastedive.com/api/similar?q=Coco&limit=5&info=1", + "Testing that the url is: https://tastedive.com/api/similar?q=Coco&limit=5&info=1", ) self.assertEqual(results, 5, "Testing that results is assigned correctly.") self.assertEqual(len(similar_movies), 5, "Testing that similar_movies are: 5") diff --git a/_sources/lectures/TWP45/TWP45_4.rst b/_sources/lectures/TWP45/TWP45_4.rst index 802d93244e..178a1628ed 100644 --- a/_sources/lectures/TWP45/TWP45_4.rst +++ b/_sources/lectures/TWP45/TWP45_4.rst @@ -5,6 +5,7 @@ Probando la API de University Domains contiene dominios, nombres y países de la mayoría de las universidades del mundo. .. activecode:: ac_l45_4a + :nocodelens: :language: python3 :python3_interpreter: brython @@ -16,7 +17,7 @@ contiene dominios, nombres y países de la mayoría de las universidades del mu import urllib.parse import json - api_url = "https://cors.bridged.cc/http://universities.hipolabs.com/search?" + api_url = "http://universities.hipolabs.com/search?" parametros = urllib.parse.urlencode({"name": "middle", "country": "turkey"}) solicitud = urllib.request.urlopen(api_url + parametros) @@ -35,7 +36,7 @@ contiene dominios, nombres y países de la mayoría de las universidades del mu import requests import json - api_url = "https://cors.bridged.cc/http://universities.hipolabs.com/search" + api_url = "http://universities.hipolabs.com/search?" parametros = {"country": "colombia"} solicitud = requests.get(api_url, params=parametros) @@ -65,10 +66,3 @@ Aprendizajes | - -.. poll:: TWP45 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP45/TWP45_4_en.rst b/_sources/lectures/TWP45/TWP45_4_en.rst index 437ed88053..37ffddfb61 100644 --- a/_sources/lectures/TWP45/TWP45_4_en.rst +++ b/_sources/lectures/TWP45/TWP45_4_en.rst @@ -5,6 +5,7 @@ Testing the University Domains API domains, names, and countries of most universities around the world. .. activecode:: ac_l45_4a_en + :nocodelens: :language: python3 :python3_interpreter: brython @@ -16,7 +17,7 @@ domains, names, and countries of most universities around the world. import urllib.parse import json - api_url = "https://cors.bridged.cc/http://universities.hipolabs.com/search?" + api_url = "http://universities.hipolabs.com/search?" params = urllib.parse.urlencode({"name": "middle", "country": "turkey"}) request = urllib.request.urlopen(api_url + params) @@ -35,7 +36,7 @@ domains, names, and countries of most universities around the world. import requests import json - api_url = "https://cors.bridged.cc/http://universities.hipolabs.com/search" + api_url = "http://universities.hipolabs.com/search?" params = {"country": "colombia"} request = requests.get(api_url, params=params) @@ -61,11 +62,4 @@ Learnings + The ``dumps`` method of ``json`` is useful if we want to visualize the response of an API in a readable way. This is achieved with the ``indent`` argument. -| - -.. poll:: TWP45E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? +| \ No newline at end of file diff --git a/_sources/lectures/TWP47/TWP47_5.rst b/_sources/lectures/TWP47/TWP47_5.rst index e08670d4d2..3e859851b2 100644 --- a/_sources/lectures/TWP47/TWP47_5.rst +++ b/_sources/lectures/TWP47/TWP47_5.rst @@ -57,10 +57,3 @@ Resultado :width: 22.859cm :align: center :alt: - -.. poll:: TWP47 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP47/TWP47_5_en.rst b/_sources/lectures/TWP47/TWP47_5_en.rst index 5e905b9fac..adf742b372 100644 --- a/_sources/lectures/TWP47/TWP47_5_en.rst +++ b/_sources/lectures/TWP47/TWP47_5_en.rst @@ -54,12 +54,4 @@ Result :height: 11.324cm :width: 22.859cm :align: center - :alt: - - -.. poll:: TWP47E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? + :alt: \ No newline at end of file diff --git a/_sources/lectures/TWP50/TWP50_4.rst b/_sources/lectures/TWP50/TWP50_4.rst index d203339884..d827e60253 100644 --- a/_sources/lectures/TWP50/TWP50_4.rst +++ b/_sources/lectures/TWP50/TWP50_4.rst @@ -139,14 +139,6 @@ Recuerda + Uso de las funcionalidades con el componente de ``brython``. + No es la única forma de crear interfaces gráficas. -+ Uso de la biblioteca de terceros: ``pygame`` y ``tkinter``. + + Uso de la biblioteca de terceros: ``pygame`` y ``tkinter``. + Para manejar los eventos se usa un controlador de eventos. -+ Controlador de eventos: función que se ejecuta cuando ocurre el evento. - -.. poll:: TWP50 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? - + + Controlador de eventos: función que se ejecuta cuando ocurre el evento. diff --git a/_sources/lectures/TWP50/TWP50_4_en.rst b/_sources/lectures/TWP50/TWP50_4_en.rst index bb64c9d89e..a6aa1d81c7 100644 --- a/_sources/lectures/TWP50/TWP50_4_en.rst +++ b/_sources/lectures/TWP50/TWP50_4_en.rst @@ -141,11 +141,4 @@ Remember + It is not the only way to create graphical interfaces. + Use of third-party library: ``pygame`` and ``tkinter``. + To handle events, an event controller is used. - + Event controller: function that is executed when the event occurs. - -.. poll:: TWP50E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? + + Event controller: function that is executed when the event occurs. \ No newline at end of file diff --git a/_sources/lectures/TWP52.rst b/_sources/lectures/TWP52.rst index f5ec1d543d..7e3e88b6ad 100644 --- a/_sources/lectures/TWP52.rst +++ b/_sources/lectures/TWP52.rst @@ -27,37 +27,50 @@ HEAD-Ex Logística y Transporte HEAD-Ex Logística y Transporte ============================== -.. activecode:: ac_l52_1a - :nocodelens: - :language: python3 - :python3_interpreter: brython - from browser import document, html +.. code-block :: python - def guardar_datos(evento): - # Agrega tu lógica para guardar datos aquí - print(f"Destino: {destino.value}, Descripción: {descripcion.value}, Hablar a: {direccion.value}") + + def salvar_dados(): + fileD = open('encomendas.txt','a') + fileD.write('Destino: ') + fileD.write('%s\n' %destino.get()) + fileD.write('Descripcion: ') + fileD.write('%s\n' %descricao.get()) + fileD.write('Habla a: ') + fileD.write('%s\n' %endereco.get('1.0',END)) + destino.delete(0,END) + descricao.delete(0,END) + endereco.delete('1.0',END) - app = html.DIV() - app <= html.H2('HEAD-Ex Logística y Transporte') - app <= html.LABEL('Destino: ') - destino = html.INPUT() - app <= destino - app <= html.LABEL('Descripción: ') - descripcion = html.INPUT() - app <= descripcion +HEAD-Ex Logística y Transporte +============================== + + +.. code-block :: python + + from tkinter import * + + app = Tk() + app.title('HEAD-Ex Logística y Transporte') + app.geometry("250x180+200+100") - app <= html.LABEL('Hablar a: ') - direccion = html.INPUT() - app <= direccion + Label(app,text = "Destino: ").pack() + destino = Entry(app) + destino.pack() - boton = html.BUTTON('Guardar') - boton.bind('click', guardar_datos) - app <= boton + Label(app,text = "Descripcion: ").pack() + descricao = Entry(app) + descricao.pack() - document <= app + Label(app,text = "Habla a: ").pack() + endereco = Entry(app) + endereco.pack() + + Button(app, text = "Salvar" , command = salvar_dados).pack() + app.mainloop() HEAD-Ex Logística e Transporte @@ -141,29 +154,14 @@ HEAD-Ex Logística y Transporte + Vision es el botón de radio presentado + Control es el código tkinter que gestiona todo esto -.. activecode:: ac_l52_1b - :nocodelens: - :language: python3 - :python3_interpreter: brython - - from browser import document, html - - def al_cambiar(evento): - print(f"Destino: {evento.target.value}") - - app = html.DIV() - - app <= html.LABEL('Destino: ') +.. code-block :: python - destinos = ['Cambridge, MA', 'Cambridge, UK', 'Seattle, WA'] - for destino in destinos: - radio = html.INPUT(Type="radio", name="destino", value=destino) - radio.bind('change', al_cambiar) - app <= radio - app <= html.LABEL(destino) - app <= html.BR() - - document <= app + Label(app, text = 'Destino: ').pack() + destino = StringVar() + destino.set(None) + Radiobutton(app, variable = destino , text = 'Cambridge , MA', value = 'Cambridge , MA').pack() + Radiobutton(app, variable = destino , text = 'Cambridge , UK', value = 'Cambridge , UK').pack() + Radiobutton(app, variable = destino , text = 'Seattle, WA', value = 'Seattle , WA').pack() HEAD-Ex Logística e Transporte @@ -194,91 +192,55 @@ HEAD-Ex Logística e Transporte ============================== -.. activecode:: ac_l52_1c - :nocodelens: - :language: python3 - :python3_interpreter: brython - - from browser import document, html, window +.. code-block :: python - def guardar_datos(evento): - window.localStorage['Destino'] = destino.value - window.localStorage['Descripción'] = descripcion.value - window.localStorage['Dirección'] = direccion.value - destino.value = '' - descripcion.value = '' - direccion.value = '' + + def salvar_dados(): + fileD = open('encomendas.txt','a') + fileD.write('Destino: ') + fileD.write('%s\n' %destino.get()) + fileD.write('Descricao: ') + fileD.write('%s\n' %descricao.get()) + fileD.write('Endereco: ') + fileD.write('%s\n' %endereco.get('1.0',END)) + destino.delete(0,END) + descricao.delete(0,END) + endereco.delete('1.0',END) - def leer_destinos(): + def ler_destinos(archivo): destinos = [] - for clave in window.localStorage: - destinos.append(window.localStorage[clave]) + f = open(archivo) + for linha in f: + destinos.append(linha.rstrip()) return destinos - app = html.DIV() - - app <= html.LABEL('Destino: ') - destino = html.INPUT() - app <= destino - - app <= html.LABEL('Descripción: ') - descripcion = html.INPUT() - app <= descripcion - - app <= html.LABEL('Dirección: ') - direccion = html.TEXTAREA() - app <= direccion - - boton = html.BUTTON('Guardar') - boton.bind('click', guardar_datos) - app <= boton - - document <= app - HEAD-Ex Logística e Transporte ============================== -.. activecode:: ac_l52_1d - :nocodelens: - :language: python3 - :python3_interpreter: brython - - from browser import document, html, window, console - - def guardar_datos(evento): - window.localStorage['Destino'] = destino.value - window.localStorage['Descripción'] = descripcion.value - window.localStorage['Dirección'] = direccion.value - console.log(f"Datos guardados: Destino - {destino.value}, Descripción - {descripcion.value}, Dirección - {direccion.value}") - destino.value = '' - descripcion.value = '' - direccion.value = '' - - app = html.DIV() - app <= html.H2('HEAD-Ex Logística y Transporte') +.. code-block :: python - app <= html.LABEL('Destino: ') - destino = html.SELECT() - opciones = ["Opción 1", "Opción 2", "Opción 3"] # Reemplaza con tus opciones - for opcion in opciones: - destino <= html.OPTION(opcion) - app <= destino + from tkinter import * - app <= html.LABEL('Descripción: ') - descripcion = html.INPUT() - app <= descripcion + app = Tk() + app.title('HEAD-Ex Logística e Transporte') + Label(app,text = "Destino: ").pack() + destino = StringVar() + destino.set(None) - app <= html.LABEL('Hablar a: ') - direccion = html.INPUT() - app <= direccion + opcoes = ler_destinos("cidades.txt") + OptionMenu(app,destino,*opcoes).pack() - boton = html.BUTTON('Guardar') - boton.bind('click', guardar_datos) - app <= boton + Label(app,text = "Descripcion: ").pack() + descricao = Entry(app) + descricao.pack() + Label(app,text = "Habla a: ").pack() + endereco = Entry(app) + endereco.pack() + Button(app, text = "Ahorrar" , command = salvar_dados).pack() + app.mainloop() - document <= app HEAD-Ex Logística y Transporte diff --git a/_sources/lectures/TWP52_en.rst b/_sources/lectures/TWP52_en.rst index e19079513c..372050b500 100644 --- a/_sources/lectures/TWP52_en.rst +++ b/_sources/lectures/TWP52_en.rst @@ -23,40 +23,54 @@ HEAD-Ex Logistics and Transportation :alt: + +HEAD-Ex Logistics and Transportation +==================================== + + +.. code-block :: python + + + def salvar_dados(): + fileD = open('encomendas.txt','a') + fileD.write('Destino: ') + fileD.write('%s\n' %destino.get()) + fileD.write('Descripcion: ') + fileD.write('%s\n' %descricao.get()) + fileD.write('Habla a: ') + fileD.write('%s\n' %endereco.get('1.0',END)) + destino.delete(0,END) + descricao.delete(0,END) + endereco.delete('1.0',END) + + + HEAD-Ex Logistics and Transportation ==================================== -.. activecode:: ac_l52_1a_en - :nocodelens: - :language: python3 - :python3_interpreter: brython - from browser import document, html +.. code-block :: python - def save_data(event): - # Add your save data logic here - print(f"Destination: {destination.value}, Description: {description.value}, Speak to: {address.value}") - - app = html.DIV() - app <= html.H2('HEAD-Ex Logistics and Transport') + from tkinter import * - app <= html.LABEL('Destination: ') - destination = html.INPUT() - app <= destination + app = Tk() + app.title('HEAD-Ex Logística y Transporte') + app.geometry("250x180+200+100") - app <= html.LABEL('Description: ') - description = html.INPUT() - app <= description + Label(app,text = "Destino: ").pack() + destino = Entry(app) + destino.pack() - app <= html.LABEL('Speak to: ') - address = html.INPUT() - app <= address + Label(app,text = "Descripcion: ").pack() + descricao = Entry(app) + descricao.pack() - button = html.BUTTON('Save') - button.bind('click', save_data) - app <= button + Label(app,text = "Habla a: ").pack() + endereco = Entry(app) + endereco.pack() - document <= app + Button(app, text = "Salvar" , command = salvar_dados).pack() + app.mainloop() HEAD-Ex Logistics and Transportation @@ -140,29 +154,14 @@ HEAD-Ex Logistics and Transportation + Vision is the featured radio button + Control is the tkinter code that manages all this -.. activecode:: ac_l52_1b_en - :nocodelens: - :language: python3 - :python3_interpreter: brython - - from browser import document, html - - def on_change(event): - print(f"Destination: {event.target.value}") - - app = html.DIV() - - app <= html.LABEL('Destination: ') +.. code-block :: python - destinations = ['Cambridge, MA', 'Cambridge, UK', 'Seattle, WA'] - for destination in destinations: - radio = html.INPUT(Type="radio", name="destination", value=destination) - radio.bind('change', on_change) - app <= radio - app <= html.LABEL(destination) - app <= html.BR() - - document <= app + Label(app, text = 'Destino: ').pack() + destino = StringVar() + destino.set(None) + Radiobutton(app, variable = destino , text = 'Cambridge , MA', value = 'Cambridge , MA').pack() + Radiobutton(app, variable = destino , text = 'Cambridge , UK', value = 'Cambridge , UK').pack() + Radiobutton(app, variable = destino , text = 'Seattle, WA', value = 'Seattle , WA').pack() HEAD-Ex Logistics and Transportation @@ -192,92 +191,54 @@ HEAD-Ex Logistics and Transportation ==================================== -.. activecode:: ac_l52_1c_en - :nocodelens: - :language: python3 - :python3_interpreter: brython +.. code-block :: python - from browser import document, html, window - - def save_data(event): - window.localStorage['Destination'] = destination.value - window.localStorage['Description'] = description.value - window.localStorage['Address'] = address.value - destination.value = '' - description.value = '' - address.value = '' - - def read_destinations(): - destinations = [] - for key in window.localStorage: - destinations.append(window.localStorage[key]) - return destinations - - app = html.DIV() - - app <= html.LABEL('Destination: ') - destination = html.INPUT() - app <= destination - - app <= html.LABEL('Description: ') - description = html.INPUT() - app <= description - - app <= html.LABEL('Address: ') - address = html.TEXTAREA() - app <= address - - button = html.BUTTON('Save') - button.bind('click', save_data) - app <= button - - document <= app + def salvar_dados(): + fileD = open('encomendas.txt','a') + fileD.write('Destino: ') + fileD.write('%s\n' %destino.get()) + fileD.write('Descricao: ') + fileD.write('%s\n' %descricao.get()) + fileD.write('Endereco: ') + fileD.write('%s\n' %endereco.get('1.0',END)) + destino.delete(0,END) + descricao.delete(0,END) + endereco.delete('1.0',END) + + def ler_destinos(archivo): + destinos = [] + f = open(archivo) + for linha in f: + destinos.append(linha.rstrip()) + return destinos HEAD-Ex Logistics and Transportation ==================================== -.. activecode:: ac_l52_1d_en - :nocodelens: - :language: python3 - :python3_interpreter: brython - - from browser import document, html, window, console - - def save_data(event): - window.localStorage['Destination'] = destination.value - window.localStorage['Description'] = description.value - window.localStorage['Address'] = address.value - console.log(f"Saved data: Destination - {destination.value}, Description - {description.value}, Address - {address.value}") - destination.value = '' - description.value = '' - address.value = '' - - app = html.DIV() - app <= html.H2('HEAD-Ex Logistics and Transport') - - app <= html.LABEL('Destination: ') - destination = html.SELECT() - options = ["Option 1", "Option 2", "Option 3"] # Replace with your options - for option in options: - destination <= html.OPTION(option) - app <= destination +.. code-block :: python - app <= html.LABEL('Description: ') - description = html.INPUT() - app <= description + from tkinter import * - app <= html.LABEL('Speak to: ') - address = html.INPUT() - app <= address + app = Tk() + app.title('HEAD-Ex Logística e Transporte') + Label(app,text = "Destino: ").pack() + destino = StringVar() + destino.set(None) - button = html.BUTTON('Save') - button.bind('click', save_data) - app <= button + opcoes = ler_destinos("cidades.txt") + OptionMenu(app,destino,*opcoes).pack() - document <= app + Label(app,text = "Descripcion: ").pack() + descricao = Entry(app) + descricao.pack() + Label(app,text = "Habla a: ").pack() + endereco = Entry(app) + endereco.pack() + Button(app, text = "Ahorrar" , command = salvar_dados).pack() + app.mainloop() @@ -292,7 +253,7 @@ HEAD-Ex Logistics and Transportation :alt: -Review +review ====== diff --git a/_sources/lectures/TWP54/TWP54_2.rst b/_sources/lectures/TWP54/TWP54_2.rst index 179b0f617c..ff74dc7d14 100644 --- a/_sources/lectures/TWP54/TWP54_2.rst +++ b/_sources/lectures/TWP54/TWP54_2.rst @@ -21,31 +21,24 @@ Atrapando la excepción Manejo de excepciones --------------------- -.. activecode:: ac_l54_2a - :nocodelens: - :language: python3 - :python3_interpreter: brython +.. code-block :: python - from browser import window, prompt, alert - - def guardar_datos(): + def salvar_dados(): try: - destino = prompt("Ingrese Destino") - if not destino: - raise ValueError("El destino no puede estar vacío") - window.sessionStorage["Destino"] = destino - descripcion = prompt("Ingrese Descripción") - if not descripcion: - raise ValueError("La descripción no puede estar vacía") - window.sessionStorage["Descripción"] = descripcion - discurso = prompt("Ingrese Discurso") - if not discurso: - raise ValueError("El discurso no puede estar vacío") - window.sessionStorage["Discurso"] = discurso - except Exception as excepcion: - alert(f'Error: {excepcion}') - - guardar_datos() + fileD = open("encomendas.txt","a") + fileD.write("Destino:\n") + fileD.write("%s\n" %destino.get()) + fileD.write("Descripcion:\n") + fileD.write("%s\n" %descripcion.get()) + fileD.write("Habla:\n") + fileD.write("%s\n" %Habla.get("1.0",END)) + destino.set(None) + descricao.delete(0,END) + endereco.delete("1.0",END) + except Excepción como excepciones: + app.title('archivo de grabación %s' %excepcion) + + + Obs.: para você testar a exceção deverá alterar as propriedades do arquivo diff --git a/_sources/lectures/TWP54/TWP54_2_en.rst b/_sources/lectures/TWP54/TWP54_2_en.rst index 6d4fb67b12..dbc2705035 100644 --- a/_sources/lectures/TWP54/TWP54_2_en.rst +++ b/_sources/lectures/TWP54/TWP54_2_en.rst @@ -21,31 +21,23 @@ Catching the Exception Handling Exceptions --------------------- -.. activecode:: ac_l54_2a_en - :nocodelens: - :language: python3 - :python3_interpreter: brython - - from browser import window, prompt, alert +.. code-block :: python def save_data(): try: - destination = prompt("Enter Destination") - if not destination: - raise ValueError("Destination cannot be empty") - window.sessionStorage["Destination"] = destination - description= prompt("Enter Description") - if not description: - raise ValueError("Description cannot be empty") - window.sessionStorage["Description"] = description - speech= prompt("Enter Speech") - if not speech: - raise ValueError("Speech cannot be empty") - window.sessionStorage["Speech"] = speech + fileD = open("orders.txt","a") + fileD.write("Destination:\n") + fileD.write("%s\n" %destination.get()) + fileD.write("Description:\n") + fileD.write("%s\n" %description.get()) + fileD.write("Speech:\n") + fileD.write("%s\n" %Speech.get("1.0",END)) + destination.set(None) + description.delete(0,END) + address.delete("1.0",END) except Exception as exception: - alert(f'Error: {exception}') + app.title('Recording file %s' %exception) - save_data() + Note: to test the exception you will need to change the properties of the file diff --git a/_sources/lectures/TWP54/TWP54_3.rst b/_sources/lectures/TWP54/TWP54_3.rst index 79cb0ba70c..3ea13373a6 100644 --- a/_sources/lectures/TWP54/TWP54_3.rst +++ b/_sources/lectures/TWP54/TWP54_3.rst @@ -1,47 +1,23 @@ Usando un messagebox ==================== -.. activecode:: ac_l54_3a - :nocodelens: - :language: python3 - :python3_interpreter: brython +.. code-block :: python - from browser import document, alert, window, html - - def guardar_datos(event): + def salvar_dados(): try: - destino = entrada_destino.value - descripcion = entrada_descripcion.value - direccion = entrada_direccion.value - - if not destino or not descripcion or not direccion: - raise ValueError("Todos los campos deben estar llenos") - - window.sessionStorage["Destino"] = destino - window.sessionStorage["Descripción"] = descripcion - window.sessionStorage["Dirección"] = direccion - except Exception as excepcion: - alert(f'Error: {excepcion}') - - app = html.DIV() - - app <= html.LABEL('Destino: ') - entrada_destino = html.INPUT() - app <= entrada_destino + fileD = open("encomendas.txt","a") + fileD.write("Destino:\n") + fileD.write("%s\n" %destino.get()) + fileD.write("Descricao:\n") + fileD.write("%s\n" %descricao.get()) + fileD.write("Endereco:\n") + fileD.write("%s\n" %endereco.get("1.0",END)) + destino.set(None) + descricao.delete(0,END) + endereco.delete("1.0",END) + except Exception as excecao: + app.title('Erro de gravacao no arquivo %s' %excecao) - app <= html.LABEL('Descripción: ') - entrada_descripcion = html.INPUT() - app <= entrada_descripcion - - app <= html.LABEL('Dirección: ') - entrada_direccion = html.INPUT() - app <= entrada_direccion - - boton = html.BUTTON('Guardar') - boton.bind('click', guardar_datos) - app <= boton - - document <= app .. image:: ../img/TWP54_009.jpg :height: 8.042cm @@ -55,10 +31,3 @@ Usando un messagebox :width: 13.348cm :align: center :alt: - -.. poll:: TWP54 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP54/TWP54_3_en.rst b/_sources/lectures/TWP54/TWP54_3_en.rst index 8cead5e302..6d9f961992 100644 --- a/_sources/lectures/TWP54/TWP54_3_en.rst +++ b/_sources/lectures/TWP54/TWP54_3_en.rst @@ -1,47 +1,22 @@ Using a messagebox ==================== -.. activecode:: ac_l54_3a_en - :nocodelens: - :language: python3 - :python3_interpreter: brython +.. code-block:: python - from browser import document, alert, window, html - - def save_data(event): + def save_data(): try: - destination = destination_input.value - description = description_input.value - address = address_input.value - - if not destination or not description or not address: - raise ValueError("All fields must be filled") - - window.sessionStorage["Destination"] = destination - window.sessionStorage["Description"] = description - window.sessionStorage["Address"] = address + fileD = open("orders.txt","a") + fileD.write("Destination:\n") + fileD.write("%s\n" %destination.get()) + fileD.write("Description:\n") + fileD.write("%s\n" %description.get()) + fileD.write("Address:\n") + fileD.write("%s\n" %address.get("1.0",END)) + destination.set(None) + description.delete(0,END) + address.delete("1.0",END) except Exception as exception: - alert(f'Error: {exception}') - - app = html.DIV() - - app <= html.LABEL('Destination: ') - destination_input = html.INPUT() - app <= destination_input - - app <= html.LABEL('Description: ') - description_input = html.INPUT() - app <= description_input - - app <= html.LABEL('Address: ') - address_input = html.INPUT() - app <= address_input - - button = html.BUTTON('Save') - button.bind('click', save_data) - app <= button - - document <= app + app.title('File writing error: %s' %exception) .. image:: ../img/TWP54_009.jpg @@ -55,11 +30,4 @@ Using a messagebox :height: 15.573cm :width: 13.348cm :align: center - :alt: - -.. poll:: TWP54E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? + :alt: \ No newline at end of file diff --git a/_sources/lectures/TWP56/TWP56_3.rst b/_sources/lectures/TWP56/TWP56_3.rst index 264f2bc6dd..52885c6434 100644 --- a/_sources/lectures/TWP56/TWP56_3.rst +++ b/_sources/lectures/TWP56/TWP56_3.rst @@ -59,10 +59,3 @@ Recuerda + DoubleVar() + Checkbutton() + Scale() - -.. poll:: TWP56 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? diff --git a/_sources/lectures/TWP56/TWP56_3_en.rst b/_sources/lectures/TWP56/TWP56_3_en.rst index d07a485ba2..1015729af8 100644 --- a/_sources/lectures/TWP56/TWP56_3_en.rst +++ b/_sources/lectures/TWP56/TWP56_3_en.rst @@ -58,11 +58,4 @@ Remember + app.destroy() + DoubleVar() + Checkbutton() -+ Scale() - -.. poll:: TWP56E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? ++ Scale() \ No newline at end of file diff --git a/_sources/lectures/TWP58/TWP58_2.rst b/_sources/lectures/TWP58/TWP58_2.rst index 6572094c60..f618023471 100644 --- a/_sources/lectures/TWP58/TWP58_2.rst +++ b/_sources/lectures/TWP58/TWP58_2.rst @@ -99,11 +99,3 @@ Recuerda + class – comienza la definición de una clase + self – autoasignado al objeto actual + __init__() Se llama al crear el objeto - -.. poll:: TWP58 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? - diff --git a/_sources/lectures/TWP58/TWP58_2_en.rst b/_sources/lectures/TWP58/TWP58_2_en.rst index b9296a7859..0749d9c13d 100644 --- a/_sources/lectures/TWP58/TWP58_2_en.rst +++ b/_sources/lectures/TWP58/TWP58_2_en.rst @@ -98,11 +98,4 @@ Remember + Create objects = instantiate a class + class - begins the definition of a class + self - assigned to the current object -+ __init__() - called when the object is created - -.. poll:: TWP58E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? ++ __init__() - called when the object is created \ No newline at end of file diff --git a/_sources/lectures/TWP60/TWP60_6.rst b/_sources/lectures/TWP60/TWP60_6.rst index 1f90ba80dc..924c110361 100644 --- a/_sources/lectures/TWP60/TWP60_6.rst +++ b/_sources/lectures/TWP60/TWP60_6.rst @@ -160,12 +160,3 @@ MOUSEBUTTONUP es un tipo de evento que se activa cuando se suelta un botón del timer1 = timer.set_interval(main,80) -.. poll:: TWP60 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? - - - diff --git a/_sources/lectures/TWP60/TWP60_6_en.rst b/_sources/lectures/TWP60/TWP60_6_en.rst index 791357b937..50986cb19c 100644 --- a/_sources/lectures/TWP60/TWP60_6_en.rst +++ b/_sources/lectures/TWP60/TWP60_6_en.rst @@ -157,11 +157,3 @@ MOUSEBUTTONUP is an event type that is fired when a mouse button is released. timer1 = timer.set_interval(main,80) -.. poll:: TWP60E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? - - diff --git a/_sources/lectures/TWP65/TWP65_3.rst b/_sources/lectures/TWP65/TWP65_3.rst index 7af0732eca..acfdad6b23 100644 --- a/_sources/lectures/TWP65/TWP65_3.rst +++ b/_sources/lectures/TWP65/TWP65_3.rst @@ -98,11 +98,3 @@ Accesorios + Train Counter Game + Quiz Builder + EcardsOnMap (es grande...) - -.. poll:: TWP65 - :scale: 3 - :allowcomment: - - En una escala del 1 (a mejorar) al 3 (excelente), - ¿cómo calificaría este capítulo? - diff --git a/_sources/lectures/TWP65/TWP65_3_en.rst b/_sources/lectures/TWP65/TWP65_3_en.rst index ea9161d452..1f361361e2 100644 --- a/_sources/lectures/TWP65/TWP65_3_en.rst +++ b/_sources/lectures/TWP65/TWP65_3_en.rst @@ -97,11 +97,4 @@ Accessories + Sudoku Solver + Train Counter Game + Quiz Builder -+ EcardsOnMap (it's huge...) - -.. poll:: TWP65E - :scale: 3 - :allowcomment: - - On a scale from 1 (needs improvement) to 3 (excellent), - how would you rate this chapter? ++ EcardsOnMap (it's huge...) \ No newline at end of file diff --git a/_sources/quiz/Quiz1.rst b/_sources/quiz/Quiz1.rst index 44462bfd1f..502f961e63 100644 --- a/_sources/quiz/Quiz1.rst +++ b/_sources/quiz/Quiz1.rst @@ -14,17 +14,11 @@ Quiz - 1 .. activecode:: q1_1 :nocodelens: - Haga un programa que dado dos números enteros, devuelva la suma de esos dos números. |br| - * Reemplazar los `...` por la fórmula correspondiente. - * Los números son dados en las variables n y m (parámetros) + Haga un programa que pida dos números enteros e imprima la suma de esos dos números. |br| ~~~~ def suma(n, m): - resultado = ... - return resultado - # Ejemplo para comprobación: - print("El resultado es:", suma(2, 3)) ==== from unittest.gui import TestCaseGui @@ -175,7 +169,7 @@ Quiz - 1 def testOne(self): self.assertEqual(tiempo(5, 5), 1, "Esperado: 1") - self.assertEqual(round(tiempo(100, 3), 2), 33.33, "Esperado: 33.33") + self.assertEqual(tiempo(100, 3), 100/3, "Esperado: " + str(100/3)) self.assertEqual(tiempo(10500, 30), 350, "Esperado: 350") self.assertEqual(tiempo(8600, 50), 172, "Esperado: 172") self.assertEqual(tiempo(130, 200), 0.65, "Esperado: 0.65") @@ -230,11 +224,11 @@ Quiz - 1 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(round(fahrenheit_a_celsius(21), 2), round(((21 - 32) * 5) / 9, 2), "Esperado: %.2f" % (((21 - 32) * 5) / 9)) - self.assertEqual(round(fahrenheit_a_celsius(108), 2), round(((108 - 32) * 5) / 9, 2), "Esperado: %.2f" % (((108 - 32) * 5) / 9)) - self.assertEqual(round(fahrenheit_a_celsius(0), 2), round(((0 - 32) * 5) / 9, 2), "Esperado: %.2f" % (((0 - 32) * 5) / 9)) - self.assertEqual(round(fahrenheit_a_celsius(-10), 2), round(((-10 - 32) * 5) / 9, 2), "Esperado: %.2f" % (((-10 - 32) * 5) / 9)) - self.assertEqual(round(fahrenheit_a_celsius(14), 2), round(((14 - 32) * 5) / 9, 2), "Esperado: %.2f" % (((14 - 32) * 5) / 9)) + self.assertEqual(fahrenheit_a_celsius(21), ((21 - 32) * 5) / 9, "Esperado: " + str(((21 - 32) * 5) / 9)) + self.assertEqual(fahrenheit_a_celsius(108), ((108 - 32) * 5) / 9, "Esperado: " + str(((108 - 32) * 5) / 9)) + self.assertEqual(fahrenheit_a_celsius(0), ((0 - 32) * 5) / 9, "Esperado: " + str(((0 - 32) * 5) / 9)) + self.assertEqual(fahrenheit_a_celsius(-10), ((-10 - 32) * 5) / 9, "Esperado: " + str(((-10 - 32) * 5) / 9)) + self.assertEqual(fahrenheit_a_celsius(14), ((14 - 32) * 5) / 9, "Esperado: " + str(((14 - 32) * 5) / 9)) myTests().main() @@ -248,7 +242,7 @@ Quiz - 1 Escriba un programa que pregunte por la cantidad de kilómetros recorridos por un automóvil alquilado, así como el número de días que ha estado alquilado el coche. Calcule el precio a pagar, sabiendo que el coche cuesta R $ 60,00 - por día y $ 0,15 por km recorrido. |br| + por día y R $ 0,15 por km recorrido. |br| ~~~~ def precio(km, dias): @@ -292,10 +286,12 @@ Quiz - 1 class myTests(TestCaseGui): def testOne(self): - for c, a, e in ((10, 1, 25.35), (3, 5, 38.02), (1, 8, 20.28), (2, 3, 15.21)): - self.assertEqual( - round(fumador(c, a), 2), e, "Esperado: %.2f para %d cig. en %d años" % (e, c, a) - ) + self.assertEqual( + fumador(10, 1), ((10 * 1 * 365) * 10) / 1440, "Esperado: " + str(((10 * 1 * 365) * 10) / 1440) + ) + self.assertEqual(fumador(3, 5), ((3 * 5 * 365) * 10) / 1440, "Esperado: " + str(((3 * 5 * 365) * 10) / 1440)) + self.assertEqual(fumador(1, 8), ((1 * 8 * 365) * 10) / 1440, "Esperado: " + str(((1 * 8 * 365) * 10) / 1440)) + self.assertEqual(fumador(2, 3), ((2 * 3 * 365) * 10) / 1440, "Esperado: " + str(((2 * 3 * 365) * 10) / 1440)) myTests().main() @@ -307,7 +303,7 @@ Quiz - 1 :nocodelens: Sabiendo que ``str()`` convierte valores numéricos en cadenas, - calcule cuántos dígitos hay en 2 elevado a la potencia de mil. |br| + calcule cuántos dígitos hay en 2 elevados a un millón. |br| ~~~~ def digitos(): @@ -320,7 +316,7 @@ Quiz - 1 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(digitos(), 302, "Esperado: 302 digitos") + self.assertEqual(digitos(), 301030, "Esperado: 301030") myTests().main() diff --git a/build_info b/build_info new file mode 100644 index 0000000000..1d0fe84223 --- /dev/null +++ b/build_info @@ -0,0 +1 @@ +unknown-0-0 diff --git a/requirements.txt b/requirements.txt index 9b9937c296..9310bc4c75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ git+https://github.com/PyAr/RunestoneComponents.git@master#runestone pytest==6.2.4 -playwright==1.18.0 +playwright==1.11.2 pytest-playwright==0.1.1 pytest-html==3.1.1 pytest-vcr==1.0.2 diff --git a/tests/test_TWP30.py b/tests/test_TWP30.py deleted file mode 100644 index 1c19e1d4a0..0000000000 --- a/tests/test_TWP30.py +++ /dev/null @@ -1,28 +0,0 @@ -def test_l30_5(page): - import time - page.goto("lectures/TWP30/TWP30_5.html") - page.click("text=5. Repeticiones¶") - page.once("dialog", lambda dialog: dialog.accept(g)) - g='42' - page.click("#ac_l30_5 >> *css=button >> text=Save & Run") - page.click("text=Ingrese un numero") - page.keyboard.type(g) - page.keyboard.press("Enter") - time.sleep(2) - assert page.inner_text("#ac_l30_5 div div:has-text(\"¡Bienvenido!¡Ganaste!Fin del juego!\")") - - -def test_l30_6(page): - from random import randint - import time - page.goto("lectures/TWP30/TWP30_6.html") - page.click("text=6. Sortear el número a adivinar¶") - page.once("dialog", lambda dialog: dialog.accept(g)) - i = randint(1, 100) - g=str(i) - page.click("#ac_l30_6 >> *css=button >> text=Save & Run") - page.click("text=Ingrese un numero") - page.keyboard.type(g) - page.keyboard.press("Enter") - time.sleep(2) - assert page.inner_text("#ac_l30_6 div div:has-text(\"¡Bienvenido!\")") diff --git a/tests/test_TWP52.py b/tests/test_TWP52.py deleted file mode 100644 index 84949542c4..0000000000 --- a/tests/test_TWP52.py +++ /dev/null @@ -1,213 +0,0 @@ -def test_l52_1(page): - page.goto("lectures/TWP52_en.html") - - # Run the exercise - page.click("#ac_l52_1a_en >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('iframe') - - # Get the iframe - frame = page.frame(url="about:srcdoc") - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - # Interact with the iframe - frame.click("input") - frame.fill("input", "Lisbon") - frame.click(":nth-match(input, 2)") - frame.fill(":nth-match(input, 2)", "Great Place!") - frame.click(":nth-match(input, 3)") - frame.fill(":nth-match(input, 3)", "Nico") - frame.click("text=Save") - - -def test_l52_2(page): - page.goto("lectures/TWP52.html") - - # Run the exercise - page.click("#ac_l52_1a >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('iframe') - - # Get the iframe - frame = page.frame(url="about:srcdoc") - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - # Interact with the iframe - frame.click("input") - frame.fill("input", "Lisbon") - frame.click(":nth-match(input, 2)") - frame.fill(":nth-match(input, 2)", "Great Place!") - frame.click(":nth-match(input, 3)") - frame.fill(":nth-match(input, 3)", "Nico") - frame.click("text=Guardar") - -def test_l52_3(page): - page.goto("lectures/TWP52_en.html") - - # Click #ac_l52_1b_en >> text=Run - page.click("#ac_l52_1b_en >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('//*[@id="ac_l52_1b_en"]/div/div[4]/iframe') - - # Get the iframe - iframe = page.query_selector('//*[@id="ac_l52_1b_en"]/div/div[4]/iframe') - frame = iframe.content_frame() - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - # Click input[name="destination"] - frame.click("input[name=\"destination\"]") - -def test_l52_4(page): - page.goto("lectures/TWP52.html") - - # Click #ac_l52_1b >> text=Run - page.click("#ac_l52_1b >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('//*[@id="ac_l52_1b"]/div/div[4]/iframe') - - # Get the iframe - iframe = page.query_selector('//*[@id="ac_l52_1b"]/div/div[4]/iframe') - frame = iframe.content_frame() - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - # Click input[name="destination"] - frame.click("input[name=\"destino\"]") - -def test_l52_5(page): - page.goto("lectures/TWP52_en.html") - - # Click #ac_l52_1c_en >> text=Run - page.click("#ac_l52_1c_en >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('//*[@id="ac_l52_1c_en"]/div/div[4]/iframe') - - # Get the iframe - iframe = page.query_selector('//*[@id="ac_l52_1c_en"]/div/div[4]/iframe') - frame = iframe.content_frame() - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - page.frame(url="about:srcdoc").click("input") - # Fill input - page.frame(url="about:srcdoc").fill("input", "Mumbai") - # Click :nth-match(input, 2) - page.frame(url="about:srcdoc").click(":nth-match(input, 2)") - # Fill :nth-match(input, 2) - page.frame(url="about:srcdoc").fill(":nth-match(input, 2)", "Great City!") - # Click textarea - page.frame(url="about:srcdoc").click("textarea") - # Fill textarea - page.frame(url="about:srcdoc").fill("textarea", "Taj Hotel") - # Click text=Save - page.frame(url="about:srcdoc").click("text=Save") - -def test_l52_6(page): - page.goto("lectures/TWP52.html") - - # Click #ac_l52_1c >> text=Run - page.click("#ac_l52_1c >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('//*[@id="ac_l52_1c"]/div/div[4]/iframe') - - # Get the iframe - iframe = page.query_selector('//*[@id="ac_l52_1c"]/div/div[4]/iframe') - frame = iframe.content_frame() - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - page.frame(url="about:srcdoc").click("input") - # Fill input - page.frame(url="about:srcdoc").fill("input", "Mumbai") - # Click :nth-match(input, 2) - page.frame(url="about:srcdoc").click(":nth-match(input, 2)") - # Fill :nth-match(input, 2) - page.frame(url="about:srcdoc").fill(":nth-match(input, 2)", "Great City!") - # Click textarea - page.frame(url="about:srcdoc").click("textarea") - # Fill textarea - page.frame(url="about:srcdoc").fill("textarea", "Taj Hotel") - # Click text=Save - page.frame(url="about:srcdoc").click("text=Guardar") - -def test_l52_7(page): - page.goto("lectures/TWP52_en.html") - - # Click #ac_l52_1d_en >> text=Run - page.click("#ac_l52_1d_en >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('//*[@id="ac_l52_1d_en"]/div/div[4]/iframe') - - # Get the iframe - iframe = page.query_selector('//*[@id="ac_l52_1d_en"]/div/div[4]/iframe') - frame = iframe.content_frame() - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - # Select Option 2 - page.frame(url="about:srcdoc").select_option("select", "Option 2") - # Click input - page.frame(url="about:srcdoc").click("input") - # Fill input - page.frame(url="about:srcdoc").fill("input", "Hey there") - # Click :nth-match(input, 2) - page.frame(url="about:srcdoc").click(":nth-match(input, 2)") - # Fill :nth-match(input, 2) - page.frame(url="about:srcdoc").fill(":nth-match(input, 2)", "Steve") - # Click text=Save - page.frame(url="about:srcdoc").click("text=Save") - -def test_l52_8(page): - page.goto("lectures/TWP52.html") - - # Click #ac_l52_1d_en >> text=Run - page.click("#ac_l52_1d >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('//*[@id="ac_l52_1d"]/div/div[4]/iframe') - - # Get the iframe - iframe = page.query_selector('//*[@id="ac_l52_1d"]/div/div[4]/iframe') - frame = iframe.content_frame() - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - # Select Option 2 - page.frame(url="about:srcdoc").select_option("select", "Opción 2") - # Click input - page.frame(url="about:srcdoc").click("input") - # Fill input - page.frame(url="about:srcdoc").fill("input", "Hey there") - # Click :nth-match(input, 2) - page.frame(url="about:srcdoc").click(":nth-match(input, 2)") - # Fill :nth-match(input, 2) - page.frame(url="about:srcdoc").fill(":nth-match(input, 2)", "Steve") - # Click text=Save - page.frame(url="about:srcdoc").click("text=Guardar") - diff --git a/tests/test_TWP54.py b/tests/test_TWP54.py deleted file mode 100644 index 8f13ee18d2..0000000000 --- a/tests/test_TWP54.py +++ /dev/null @@ -1,74 +0,0 @@ -def test_TWPl54_1(page): - page.goto("lectures/TWP54/TWP54_3_en.html") - - # Run the exercise - page.click("#ac_l54_3a_en >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('iframe') - - # Get the iframe - frame = page.frame(url="about:srcdoc") - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - page.frame(url="about:srcdoc").click("input") - # Fill input - page.frame(url="about:srcdoc").fill("input", "Lisbon") - # Click :nth-match(input, 2) - page.frame(url="about:srcdoc").click(":nth-match(input, 2)") - # Fill :nth-match(input, 2) - page.frame(url="about:srcdoc").fill(":nth-match(input, 2)", "Great Place!") - # Click :nth-match(input, 3) - page.frame(url="about:srcdoc").click(":nth-match(input, 3)") - # Fill :nth-match(input, 3) - page.frame(url="about:srcdoc").fill(":nth-match(input, 3)", "Wall Street") - # Click text=Save - page.frame(url="about:srcdoc").click("text=Save") - # Click :nth-match(input, 3) - page.frame(url="about:srcdoc").click(":nth-match(input, 3)") - # Fill :nth-match(input, 3) - page.frame(url="about:srcdoc").fill(":nth-match(input, 3)", "") - # Click text=Save - page.once("dialog", lambda dialog: dialog.dismiss()) - page.frame(url="about:srcdoc").click("text=Save") - -def test_TWPl54_2(page): - page.goto("lectures/TWP54/TWP54_3.html") - - # Run the exercise - page.click("#ac_l54_3a >> *css=button >> text=Run") - - # Wait for the iframe to load - page.wait_for_selector('iframe') - - # Get the iframe - frame = page.frame(url="about:srcdoc") - - # Check if the iframe was found - if frame is None: - raise Exception("Could not find iframe") - - page.frame(url="about:srcdoc").click("input") - # Fill input - page.frame(url="about:srcdoc").fill("input", "Lisbon") - # Click :nth-match(input, 2) - page.frame(url="about:srcdoc").click(":nth-match(input, 2)") - # Fill :nth-match(input, 2) - page.frame(url="about:srcdoc").fill(":nth-match(input, 2)", "Great Place!") - # Click :nth-match(input, 3) - page.frame(url="about:srcdoc").click(":nth-match(input, 3)") - # Fill :nth-match(input, 3) - page.frame(url="about:srcdoc").fill(":nth-match(input, 3)", "Wall Street") - # Click text=Save - page.frame(url="about:srcdoc").click("text=Guardar") - # Click :nth-match(input, 3) - page.frame(url="about:srcdoc").click(":nth-match(input, 3)") - # Fill :nth-match(input, 3) - page.frame(url="about:srcdoc").fill(":nth-match(input, 3)", "") - # Click text=Save - page.once("dialog", lambda dialog: dialog.dismiss()) - page.frame(url="about:srcdoc").click("text=Guardar") - diff --git a/tests/test_quiz1.py b/tests/test_quiz1.py index 32b39efdbc..8d8386b8be 100644 --- a/tests/test_quiz1.py +++ b/tests/test_quiz1.py @@ -8,11 +8,8 @@ def test_quiz1_1(page): page.click("text=Ejercicio 1") page.click("text=def suma(n, m):") page.keyboard.press("ArrowDown") - page.keyboard.press("End") - # remove ... - for i in range(3): - page.keyboard.press("Backspace") - page.keyboard.type("n + m") + page.keyboard.press("Tab") + page.keyboard.type("return n+m") # Run the exercise page.click("#q1_1 >> *css=button >> text=Run")