Advertisement
teslariu

if-else

Feb 3rd, 2022
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Hay 3 estructuras lógicas en Python:
  5. # 1 condicional (if-else)  (decisión)
  6. # 2 bucles: while (bucle indefinido)  for (bucle definido) (repeticiones)
  7.  
  8. # CONDICIONALES:
  9. # Script que pide una edad y responde si es mayor de edad o no
  10.  
  11. edad = int(input("Ingrese su edad: "))
  12.  
  13. if edad >= 18:
  14.     print("Usted es mayor de edad")
  15.     print("Felicitaciones")
  16. else:
  17.     print("Usted es menor de edad aún")
  18.     print("Que lástima....")
  19.    
  20. # Script que pide ingresar un numero entero y responde si es par o impar
  21. # considere al cero como par
  22. # ayuda: considere el operador % (módulo o resto)
  23.  
  24. numero = int(input('Ingrese un numero: '))
  25.  
  26. if numero % 2 == 0:
  27.     print('El numero es par')
  28. else:
  29.     print('El numero es impar')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement