Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def citire ():
- nr=int(input("Introduceti un numar de exact 4 cifre"))
- while 1000>nr or nr >9999:
- nr=int(input("Introduceti un numar de exact 4 cifre"))
- return nr
- def obtinereCifre(n):
- a=0
- b=0
- c=0
- d=0
- a=n//1000
- b=n//100%10
- c=n//10%10
- d=n%10
- tupla=(a,b,c,d)
- return tupla
- def maxim (tupla):
- nr=0
- a=tupla[0]
- b=tupla[1]
- c=tupla[2]
- d=tupla[3]
- lista=[a,b,c,d]
- lista.sort(reverse=True)
- a=lista[0]
- b=lista[1]
- c=lista[2]
- d=lista[3]
- nr=a*1000+b*100+c*10+d
- return nr
- def minim (tupla):
- nr=0
- a=tupla[0]
- b=tupla[1]
- c=tupla[2]
- d=tupla[3]
- lista=[a,b,c,d]
- lista.sort()
- a=lista[0]
- b=lista[1]
- c=lista[2]
- d=lista[3]
- nr=a*1000+b*100+c*100+d
- return nr
- x=citire()
- t=obtinereCifre(x)
- m=minim(t)
- M=maxim(t)
- s=m+M
- print ("Numarul {} si corespondentul {}!".format(x,s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement