Advertisement
maxim_shlyahtin

new_tasks

Apr 29th, 2023
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. from math import *
  2.  
  3. #2
  4. def func(x):  # сама функция
  5.     return (1 - cos(x)) / exp(x)
  6.  
  7.  
  8. array = []  # массив, в котором будем хранить пары (значение, точка)
  9. for x in range(-5, 15):
  10.     array.append([func(x), x])  # добавляем все пары в массив
  11.  
  12. print("Where the lowest value is reached:", min(array)[1])
  13. print("The lowest value of the function:", min(array)[0])
  14.  
  15. #3
  16. fhand = open("text_3_1.txt")
  17. index = 1
  18. for i in fhand:
  19.     if index % 2 == 0:
  20.         print(int(i), end=" ")
  21.     index += 1
  22.  
  23.  
  24. #4
  25. fhand = open("test_4_1.txt")
  26. s = fhand.read()
  27. s = s.split()
  28. s1 = list(set(s))
  29. count = 0
  30. for word in s1:
  31.     for i in range(len(s)):
  32.         if word == s[i]:
  33.             count += 1
  34.     print(word, count)
  35.     count = 0
  36.  
  37.  
  38. #5
  39. import random
  40.  
  41.  
  42. def func(fhand):
  43.     n = int(input())
  44.     products = ['apple', 'banana', 'pineapple']
  45.     f = open(fhand, 'w')
  46.     for i in range(n):
  47.         ind = random.randint(0, 2)
  48.         string = products[ind] + ',' + str(random.random()) + '\n'
  49.         f.write(string)
  50.  
  51.  
  52. func('task_file.txt')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement