Advertisement
elcocodrilotito

División básica

Oct 16th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. """Dise˜nar un programa que devuelva el cociente y el resto de una divison
  2. entera suponiendo que no tenemos los operadores de divisi´on (//) y de
  3. resto( %)
  4. """
  5.  
  6. a=int(input("Dame un numero entero "))
  7. d=a
  8. b=int(input("Dame otro entero "))
  9. while b==0:
  10.     b=int(input("Lo sentimos, el denominador no puede ser 0, introduzca otro numero "))
  11. e=b
  12. print("Vamos a proceder a la división de %d/%d"%(a,b))
  13. c=0
  14. if a<0:
  15.     a=-a
  16. if b<0:
  17.     b=-b
  18. while a>=b:
  19.     a=a-b
  20.     c=c+1
  21. if d<0 and e<0:
  22.     a=-a
  23. else:
  24.     if d<0:
  25.         c=-c
  26.         a=-a
  27.     if e<0:
  28.         c=-c
  29. print("El cociente es %d y el resto %d" %(c,a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement