Xom9ik

Lab_3/16var (IV semester) .py

Mar 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import math
  2. from random import choice
  3. from string import ascii_uppercase
  4.  
  5. print("Lab_3 / 16var")
  6. print("Task 1")
  7.  
  8. a = 0.1
  9. b = 1.0
  10. h = 0.1
  11. n = 16
  12.  
  13. print(" x  |    Y(x)    |    S(x)")
  14. x = a
  15. while x <= b:
  16.     y = math.cos(x * math.sin(math.pi / 4)) * math.exp(x * math.cos(math.pi / 4))
  17.     sum = 0
  18.     k = 0
  19.     while k < n:
  20.         sum += ((math.cos(k * math.pi / 4)) / (math.factorial(k))) * x ** k
  21.         k += 1
  22.     print(x, "|", "%.8f" % y, "|", "%.8f" % sum)
  23.     x = round(x + h, 1)
  24.  
  25. print("Task 2")
  26. find = "A"
  27. rand_str = ''.join(choice(ascii_uppercase) for i in range(40))
  28. print(rand_str)
  29. print("Number of occurrences:", rand_str.count(find))
  30. while True:
  31.     num_sym = rand_str.find(find)
  32.     if (num_sym == -1):
  33.         break
  34.     tmp = rand_str[:num_sym]
  35.     for i in range(0, len(find)):
  36.         tmp += " "
  37.     tmp += rand_str[num_sym + 1:]
  38.     rand_str = tmp
  39. print(rand_str)
Add Comment
Please, Sign In to add comment