Advertisement
teslariu

template while true

Aug 22nd, 2023
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # bucle indefinido: while
  5. """
  6. i = 0
  7. while i < 5:
  8.     print(i)
  9.     continue # reinicia el ciclo
  10.     i = i + 1
  11.    
  12. print("Chau")
  13.  
  14. # script que imprime verticalmente una lista de nombres con while
  15. # no es lo ideal, habría que hacerlo con for
  16. lista_de_nombres = ["Alan", "Zoilo", "Abel", "Marta", 'Jorge', "Carina"]
  17.  
  18. i = 0
  19.  
  20. while i < len(nombres):
  21.     print(nombres[i])
  22.     i = i + 1
  23.    
  24. # SPOILER (de for):
  25. for nombre in lista_de_nombres:
  26.     print(nombre)
  27. """
  28. # Script que convierte temp de ºF a ºC y viceversa
  29.    
  30. while True:
  31.     print("""
  32.     Menu de opciones
  33.     ----------------
  34.     1. ºC -> ºF
  35.     2. ºF -> ºC
  36.     3. Salir
  37.     -------------------
  38.     """)
  39.    
  40.     opcion = input("Seleccione su opción: ")
  41.    
  42.     if opcion == "1":
  43.         temp = float(input("Temp: "))
  44.         print(f"{temp * 1.8 + 32:.1f}ºF")
  45.        
  46.     elif opcion == "2":
  47.         temp = float(input("Temp: "))
  48.         print(f"{(temp - 32) / 1.8:.1f}ºC")
  49.  
  50.  
  51.     elif opcion == "3":
  52.         print("Adios...")
  53.         break
  54.        
  55.     else:
  56.         print("Opción incorrecta..")
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement