Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Task 1.3
- x = 5 >= 2
- A = {1,3,7,8}
- B = {2,5,4,10, 'apple'}
- C = A & B
- df = 'Nicolas Coppolo', 34, 'g'
- z = 'type'
- D = ['1', 'title', 2, 'content']
- print(type(x),
- type(A),
- type(B),
- type(C),
- type(df),
- type(z),
- type(D), sep='\n')
- Task 2.3
- def interval(num):
- if num < -5: return f'{num} is in interval: (-inf, -5)'
- elif num > 5: return f'{num} is in interval: (5, +inf)'
- elif num in range(-5, 6): return f'{num} is in interval: (-5, 5)'
- def main():
- x = int(input('Enter a number: '))
- print(interval(x))
- if __name__ == '__main__':
- main()
- Task 3.3.1
- x = 10
- while x > 0:
- print(x)
- x -= 3
- Task 3.3.2
- # position = должность
- list_of_characteristics = ['age', 'sex', 'height',
- 'weight', 'position']
- for characteristic in list_of_characteristics:
- print(characteristic)
- Task 3.3.3
- list_of_digits = list(range(2, 16))
- print(list_of_digits)
- Task 3.3.4
- for i in range(105, 0, -25):
- print(i)
- Task 3.3.5
- # [0,1,2,3,4,5,6,7,8,9] ---> [8,1,6,3,4,5,2,7,0,9]
- def swap(digits):
- digits[0::2] = reversed(digits[0::2])
- return digits
- test = [0,1,2,3,4,5,6,7,8,9]
- print(swap(test))
- Task 4.3.1
- import random
- from matplotlib import pyplot as plt
- array_of_rands = [random.uniform(0, 1) for _ in range(10)]
- average = sum(array_of_rands)/len(array_of_rands)
- sorted_array = sorted(array_of_rands)
- median = (sorted_array[4]+sorted_array[5])/2
- print(f'Array: {array_of_rands}',
- f'Average value: {average}',
- f'Median value: {median}')
- plt.scatter(array_of_rands, array_of_rands)
- plt.gca().set(xlim=(0, 1), ylim=(0, 1))
- plt.show()
- Task 4.3.2
- import math
- from matplotlib import pyplot as plt
- def calc_func(x):
- form_1 = math.sqrt(1+math.exp(math.sqrt(x)) + (math.cos(x))**2)
- form_2 = abs((1-(math.sin(x))**3))
- form_3 = math.log(2*x)
- return form_1/form_2 + form_3
- x_digits = list(range(1,11))
- calc_result = [calc_func(x) for x in x_digits]
- print(calc_result)
- plot 1
- plt.subplot(2, 2, 1)
- plt.plot(x_digits, calc_result)
- plot 2
- plt.subplot(2, 2, 2)
- plt.scatter(x_digits[:5], calc_result[:5])
- plt.show()
- Task 4.3.3
- from matplotlib import pyplot as plt
- from scipy.integrate import simps
- import numpy as np
- x = np.arange(0, 10, 1)
- y = np.abs(np.cos(x*np.exp(np.cos(x) + np.log(x+1))))
- plt.grid()
- plt.plot(x, y, c='r')
- plt.fill_between(x, y)
- plt.show()
- area = np.trapz(y)
- print(area)
- Task 4.3.4
- from matplotlib import pyplot as plt
- month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec']
- microsoft = [231.96, 232.38, 235.77, 252.18, 249.68, 270.90, 284.91, 301.88, 281.92, 331.62, 330.59, 336.32]
- google = [131.96, 121.26, 122.15, 131.46, 124.61, 136.96, 145.86, 151.83, 141.50, 149.80, 165.30, 177.57]
- apple = [91.37, 101.10, 103.13, 117.68, 117.84, 122.09, 134.73, 144.70, 133.68, 148.05, 141.90, 144.85]
- fig, ax = plt.subplots()
- ax.plot(month, microsoft, label='Microsoft')
- ax.plot(month, apple, label='Apple')
- ax.plot(month, google, label='Google')
- ax.legend()
- fig.set_figheight(5)
- fig.set_figwidth(8)
- plt.show()
- Task 4.3.5
- import math
- commands = {'+': lambda x, y: x+y,
- '-': lambda x, y: x-y,
- '*': lambda x, y: x*y,
- '%': lambda x, y: x/y,
- 'e': lambda x, y: math.exp(x+y),
- 'sin': lambda x, y: math.sin(x+y),
- 'cos': lambda x, y: math.cos(x+y),
- 'pow': lambda x, y: x**y}
- def main():
- print(*['Plus: +', 'Minus: -', 'Multiply: *', 'Divide: %', 'Exponential: e', 'Sin: sin', 'Cos: cos', 'Pow: pow'], sep='\n')
- print('---------')
- expression = input('Choose one of these operands: ')
- x, y = map(int, input('Now write two numbers: ').split())
- return commands[expression](x, y)
- if __name__ == '__main__':
- print(main())
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement