Advertisement
trds

5decembrie2020

Dec 5th, 2020 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. def citire ():
  2.     nr=int(input("Introduceti un numar de exact 4 cifre"))
  3.     while 1000>nr or nr >9999:
  4.         nr=int(input("Introduceti un numar de exact 4 cifre"))
  5.     return nr
  6.  
  7. def obtinereCifre(n):
  8.     a=0
  9.     b=0
  10.     c=0
  11.     d=0
  12.     a=n//1000
  13.     b=n//100%10
  14.     c=n//10%10
  15.     d=n%10
  16.     tupla=(a,b,c,d)
  17.     return tupla
  18.  
  19. def maxim (tupla):
  20.     nr=0
  21.     a=tupla[0]
  22.     b=tupla[1]
  23.     c=tupla[2]
  24.     d=tupla[3]
  25.     lista=[a,b,c,d]
  26.     lista.sort(reverse=True)
  27.     a=lista[0]
  28.     b=lista[1]
  29.     c=lista[2]
  30.     d=lista[3]
  31.     nr=a*1000+b*100+c*10+d
  32.     return nr
  33.  
  34. def minim (tupla):
  35.     nr=0
  36.     a=tupla[0]
  37.     b=tupla[1]
  38.     c=tupla[2]
  39.     d=tupla[3]
  40.     lista=[a,b,c,d]
  41.     lista.sort()
  42.     a=lista[0]
  43.     b=lista[1]
  44.     c=lista[2]
  45.     d=lista[3]
  46.     nr=a*1000+b*100+c*100+d
  47.     return nr
  48. x=citire()
  49. t=obtinereCifre(x)
  50. m=minim(t)
  51. M=maxim(t)
  52. s=m+M
  53. print ("Numarul {} si corespondentul {}!".format(x,s))
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement