Advertisement
Spocoman

Sum And Product

Feb 20th, 2022 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. num = int(input())
  2. is_break = False
  3.  
  4. for i in range(1, 9):
  5.     for j in range(9, i, -1):
  6.         for k in range(9):
  7.             for l in range(9, k, -1):
  8.                 if (i + j + k + l) == i * j * k * l and num % 10 == 5:
  9.                     print(f"{i}{j}{k}{l}")
  10.                     is_break = True
  11.                     exit()
  12.  
  13.                 if i * j * k * l // (i + j + k + l) == 3 and num % 3 == 0:
  14.                     print(f"{l}{k}{j}{i}")
  15.                     is_break = True
  16.                     exit()
  17. if not is_break:
  18.     print("Nothing found")
  19.  
  20.  
  21. РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  22.  
  23. num = int(input())
  24. is_break = False
  25.  
  26. for i in range(1, 9):
  27.     for j in range(9, i, -1):
  28.         for k in range(9):
  29.             for l in range(9, k, -1):
  30.                 if (i + j + k + l) == i * j * k * l and num % 10 == 5 \
  31.                         or i * j * k * l // (i + j + k + l) == 3 and num % 3 == 0:
  32.                     print(f"{i}{j}{k}{l}" if (i + j + k + l) == i * j * k * l else f"{l}{k}{j}{i}")
  33.                     is_break = True
  34.                     exit()
  35.  
  36. if not is_break:
  37.     print("Nothing found")
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement