Advertisement
maxim_shlyahtin

2_list

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