Advertisement
Guest User

Mini-reto-programming | HxC | by quuim

a guest
May 1st, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.09 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. #       RetoHxC.py
  5. #      
  6. #       Copyright 2013 quuim <quuim.py@gmail.com>
  7. #   qlabs.tk/blog
  8. #      
  9. #       This program is free software; you can redistribute it and/or modify
  10. #       it under the terms of the GNU General Public License as published by
  11. #       the Free Software Foundation; either version 2 of the License, or
  12. #       (at your option) any later version.
  13. #      
  14. #       This program is distributed in the hope that it will be useful,
  15. #       but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #       GNU General Public License for more details.
  18. #      
  19. #       You should have received a copy of the GNU General Public License
  20. #       along with this program; if not, write to the Free Software
  21. #       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. #       MA 02110-1301, USA.
  23.  
  24. import os, sys # Estas librerias las usare solamente por cuestiones de estetica (os.system("clear")) asi que no creo que me descalifiquen por eso...
  25.  
  26. def main():
  27.     cadena = [1,1,1,1] #Se crea cadena con 4 enteros
  28.     try:
  29.         cadena[0] = int(raw_input("Ingrese el dato 1:")) #Se cambian los cuatro enteros por los numeros que el usuario introduzca
  30.         cadena[1] = int(raw_input("Ingrese el dato 2:"))
  31.         cadena[2] = int(raw_input("Ingrese el dato 3:"))
  32.         cadena[3] = int(raw_input("Ingrese el dato 4:"))
  33.         FuncionQueHaceElTrabajo(cadena) # Se envían los datos a la funcion que los procesará
  34.     except:
  35.         print "Ingrese un dato valido..." # Si ingresa un caracter no permitido por los integers o no ingresa nada le hará volver a introducir los valores
  36.         raw_input()
  37.         os.system("clear") # Si usas windows cambia "clear" por "cls", si usas otros sistemas operativos cambialo por el comando de limpiar pantalla
  38.         main()
  39.     return 0
  40.    
  41. def FuncionQueHaceElTrabajo(cadena):
  42.     for i in cadena:
  43.         if i==cadena[0] and i==cadena[1] and i==cadena[2] and i==cadena[3]: # Si todos los numeros son iguales avis y termina el programa
  44.             print "\n\nTodos los numeros son iguales"
  45.             raw_input()
  46.             break
  47.         if (i==cadena[0] and i==cadena[1] and i==cadena[2]) or (i==cadena[1] and i==cadena[2] and i==cadena[3]) or (i==cadena[2] and i==cadena[3] and i==cadena[0]) or (i==cadena[3] and i==cadena[0] and i==cadena[1]): # Si el numero es igual a otros 2 el programa volverá al for i in cadena
  48.             continue
  49.         else: # Si i no es igual ni a todos ni a 2 otros empieza a calcular si es más grande o pequeño que el resto
  50.             print "\n\nEl número", i, "es distinto, rianse de él"
  51.             if (i<cadena[0] and i<cadena[1] and i<cadena[2]) or (i<cadena[1] and i<cadena[2] and i<cadena[3]) or (i<cadena[2] and i<cadena[3] and i<cadena[0]) or (i<cadena[3] and i<cadena[0] and i<cadena[1]):
  52.                 print "También es el más pequeño"
  53.             if (i>cadena[0] and i>cadena[1] and i>cadena[2]) or (i>cadena[1] and i>cadena[2] and i>cadena[3]) or (i>cadena[2] and i>cadena[3] and i>cadena[0]) or (i>cadena[3] and i>cadena[0] and i>cadena[1]):
  54.                 print "También es el más grande"
  55.  
  56. if __name__ == "__main__":
  57.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement