Xom9ik

Lab_4/16var (IV semester) .py

Mar 13th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import math
  2.  
  3. print("Lab_4 / 16var")
  4. print("Task 1")
  5. while True:
  6.     try:
  7.         x = int(input("Enter x: "))
  8.         n = int(input("Enter n: "))
  9.         break
  10.     except ValueError:
  11.         print("Enter an integer")
  12.  
  13. z = 0
  14. for i in range(1, n):
  15.     if (i == 1):
  16.         z = x
  17.     elif (i % 2 == 0):
  18.         print(i, "Even")
  19.         z -= x ** i / i
  20.     else:
  21.         print(i, "Odd")
  22.         z += x ** i / i
  23.     print(z)
  24.  
  25. print("Task 2")
  26. a = 2
  27. b = 4
  28. n = 16
  29. x = a
  30. count = 0
  31.  
  32. print("count |    x    |    F1(x)   |    F2(x)")
  33. while x <= b:
  34.     count += 1
  35.     f1 = x * math.cos(x / 2)
  36.     f2 = x ** (1 / 3) + math.sqrt(2) * math.exp(-x)
  37.     print(count, "    |  ", "%.3f" % x, "|", "%.8f" % f1, "|", "%.8f" % f2)
  38.     x += (b - a) / n
Advertisement
Add Comment
Please, Sign In to add comment