Advertisement
teslariu

while True

Jul 5th, 2022
997
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # bucle indefinido: while
  5. import time
  6. """
  7. # Script que cuenta del uno al diez
  8.  
  9. n = 1
  10.  
  11. while n < 11:
  12.    print(n)
  13.    n = n + 1
  14.  
  15. # Script que cuenta en forma regresiva de 10 a 1 y luego dice BUMMM
  16. n = 10
  17.  
  18. while n > 0:
  19.    print(n)
  20.    n = n - 1
  21.    time.sleep(1)
  22.  
  23. print("BUMMM")
  24.  
  25. # Script que imprime los números múltiplos de 3 y 4 entre 1 y 100
  26. n = 1
  27. while n < 101:
  28.    if n%3==0 and n%4==0:
  29.        print(n, end=" ")
  30.    n = n +1
  31.  
  32. # la instruccion break interrumpe la ejecucion de un while:
  33. n = 1
  34.  
  35. while n<10:
  36.    print(n)
  37.    break
  38.    print("Jaja") # no se imprime, imprime 1 y sale
  39.    
  40. # la instruccion continue reinicia la ejecucion de un while (saltea)
  41. # las instrucciones posteriores:
  42. n = 1
  43. while n<10:
  44.    print(n)
  45.    continue
  46.    print("Jaja") # no se imprime, imprime 1 indefinidamente
  47. """
  48. # Script que implementa un menu de ejecución
  49. # Programa que calcule area y perimetro de diversas figuras geometricas
  50.  
  51. menu = """
  52.    Menú de opciones
  53.    ----------------
  54.    1. Cuadrado
  55.    2. Círculo
  56.    3. Triángulo
  57.    4. Salir
  58.    """
  59.  
  60. print("Calculo de áreas y perímetros")
  61. print("-----------------------------")
  62.  
  63. while True:
  64.     print(menu)
  65.     opcion = input("Seleccione una opcion: ")
  66.    
  67.     if opcion == "1":
  68.         pass
  69.    
  70.     elif opcion == "2":
  71.         radio = float(input("Ingrese el radio: "))
  72.         print(f"area: {3.1416*radio**2:.2f} - perímetro: {2*3.1416*radio:.2f}")
  73.        
  74.     elif opcion == "3":
  75.         pass # Ticket para Ariadna 5/7+10
  76.    
  77.     elif opcion == "4":
  78.         print("Adios...")
  79.         break
  80.    
  81.     else:
  82.         print("Opción incorrecta...")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement