Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from random import choice
- from string import ascii_uppercase
- print("Lab_3 / 16var")
- print("Task 1")
- a = 0.1
- b = 1.0
- h = 0.1
- n = 16
- print(" x | Y(x) | S(x)")
- x = a
- while x <= b:
- y = math.cos(x * math.sin(math.pi / 4)) * math.exp(x * math.cos(math.pi / 4))
- sum = 0
- k = 0
- while k < n:
- sum += ((math.cos(k * math.pi / 4)) / (math.factorial(k))) * x ** k
- k += 1
- print(x, "|", "%.8f" % y, "|", "%.8f" % sum)
- x = round(x + h, 1)
- print("Task 2")
- find = "A"
- rand_str = ''.join(choice(ascii_uppercase) for i in range(40))
- print(rand_str)
- print("Number of occurrences:", rand_str.count(find))
- while True:
- num_sym = rand_str.find(find)
- if (num_sym == -1):
- break
- tmp = rand_str[:num_sym]
- for i in range(0, len(find)):
- tmp += " "
- tmp += rand_str[num_sym + 1:]
- rand_str = tmp
- print(rand_str)
Add Comment
Please, Sign In to add comment