Advertisement
vasyukov

ZFTSH Programming Elements Task 9

Apr 1st, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. a, b, c, d = map(int, input().split())
  2.  
  3. one = -(a + b + c + d)
  4. two = a*b + a*c + a*d + b*c + b*d + c*d
  5. three = -(a*b*c + a*b*d + a*c*d + b*c*d)
  6. four = a*b*c*d
  7.  
  8. def f(x):
  9.     if x > 0:
  10.         if x == 1:
  11.             res = ' + '
  12.         else:
  13.             res = f' + {x}'
  14.     elif x < 0:
  15.         if x == -1:
  16.             res = ' - '
  17.         else:
  18.             res = f' - {abs(x)}'
  19.     else:
  20.         res = ''
  21.     return res
  22.  
  23. x3 = x2 = x = zero = ''
  24. if f(one) != '':
  25.     x3 = f'{f(one)}x^3'  
  26. if f(two) != '':
  27.     x2 = f'{f(two)}x^2'
  28. if f(three) != '':
  29.     x = f'{f(three)}x'
  30. if f(four) != '':
  31.     zero = f'{f(four)}'
  32.     if zero == ' + ':
  33.         zero = ' + 1'
  34.     elif zero == ' - ':
  35.         zero = ' - 1'
  36.  
  37. print('x^4', x3, x2, x, zero, sep='')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement