Xom9ik

Lab_5/15var (IV semester) .py

Apr 8th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. import math
  2.  
  3.  
  4.  
  5. print("Lab_5 / 15var")
  6. print("Task 1")
  7. def Calc_1(x):
  8.     a = math.pow(x, 2) / x
  9.     b = (2 - x) / 6
  10.     c = math.pow(math.cos(x), 3) - 2 * x
  11.     h = 5 * c + 2 * math.pow(a, 4)
  12.     return a,b,c,h
  13. while True:
  14.     try:
  15.         x = float(input("Enter x: "))
  16.         break
  17.     except ValueError:
  18.         print("Please enter a value with a floating point")
  19.  
  20. result = Calc_1(x)
  21. print("x:", x)
  22. print("a:", result[0])
  23. print("b:", result[1])
  24. print("c:", result[2])
  25. print("h:", result[3])
  26.  
  27. print("Task 2")
  28. def Calc_2(c):
  29.     z = math.cos(c)
  30.     if (z < 0):
  31.         print("z < 0")
  32.         f1 = math.pow(z, 5) / math.sin(2 * z)
  33.         y = f1
  34.     elif (0 <= z <= 8):
  35.         print("0 <= z <= 8")
  36.         f2 = math.exp(-2 * z) + math.tan(z)
  37.         y = f2
  38.     elif (z > 8):
  39.         print("z > 8")
  40.         f3 = math.pow(math.cos(z), 4) + math.pow(z, 1 / 3)
  41.         y = f3
  42.     return z,y
  43.  
  44. while True:
  45.     try:
  46.         c = float(input("Enter c: "))
  47.         break
  48.     except ValueError:
  49.         print("Please enter a value with a floating point")
  50. print("c:", c)
  51.  
  52. result = Calc_2(c)
  53. print("z:", result[0])
  54. print("y:", result[1])
  55.  
  56. print("Task 3")
  57. def Calc_3(a, b, c):
  58.     count = 0
  59.     summ = 0
  60.     print("  x  |           F1(x)         |           F2(x)         |           y            |")
  61.     while a <= b:
  62.         x = a
  63.         count += 1
  64.         f1 = math.pow(x, 3 * x + 1) + 8 * x
  65.         f2 = math.fabs(x - 8) + math.sin(x)
  66.         summ += f1 / f2
  67.         print('%4s |  %22s |  %22s | %22s |' % (x, f1, f2, summ))
  68.         a = round(a + c, 1)
  69.     return count, summ
  70.  
  71. a = 4
  72. b = 7.5
  73. c = 0.3
  74. result = Calc_3(a, b, c)
  75. print("The sum of the series after", result[0], "operations is:",  result[1])
Advertisement
Add Comment
Please, Sign In to add comment