Advertisement
teslariu

template while true

Jan 28th, 2022
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # TEMPLATE while True SIN MENU
  4.  
  5. """
  6. # Realizar un script que convierta una distancia de metros a kms"
  7. while True:
  8.    
  9.     ###################
  10.     distancia = float(input("Ingrese una distancia en metros: "))
  11.     print(f"{distancia} mts equivalen a {distancia/1000} kms")
  12.     ##################
  13.    
  14.     opcion = input("Presione cualquier tecla para continuar (o 1 para salir): ")
  15.     if opcion == "1":
  16.         print("Gracias por usar este script...")
  17.         break
  18. """
  19.  
  20. # Adaptamos el script de nros pares e impares para ejecutarlo todas
  21. # las veces que queramos
  22.  
  23. while True:
  24.    
  25.     ##########################
  26.     lista_numeros = []
  27.     impar = 0
  28.     par = 0
  29.     n = int(input("\nIngrese Un numero entero positivo: "))
  30.  
  31.     while n:
  32.         if n % 2:
  33.             impar = impar + 1
  34.         else:
  35.             par = par + 1
  36.    
  37.         lista_numeros.append(n);
  38.    
  39.         n = int(input("Ingrese otro numero entero positivo: "))
  40.        
  41.     print(f"{lista_numeros}")
  42.     print(f"Hay un total de {impar} numeros impares y un total de {par} numeros pares.")
  43.     ##################################################
  44.  
  45.     opcion = input("Presione cualquier tecla para continuar (o 1 para salir): ")
  46.     if opcion == "1":
  47.         print("Gracias por usar este script...")
  48.         break
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement