Th3NiKo

Zadanie7

Jan 30th, 2022
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. import math
  2.  
  3. # Definicja funkcji y
  4. def y(x):
  5.     if (x > -2 and x < 2) and x != -1:
  6.         return math.log(4 - x**2) / (1 + x)
  7.     elif x <= -2 or x >= 2:
  8.         return (4 - x**2) / (1 + x)
  9.     else:
  10.         return 4
  11.  
  12.  
  13. # Jednowymiara macierz wejściowa
  14. input_data = [-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13]
  15.  
  16. # Stablicować funkcję y
  17. apply_y = []
  18. for x in input_data:
  19.     apply_y.append(y(x))
  20.  
  21.  
  22. M = 4 # Ile liczb ujemnych chcemy mieć
  23. j = len(input_data) # Ilość danych liczb
  24.  
  25. # Zadanie
  26. sum = 0 # Zmienna do zliczania sumy
  27. negative_count = 0 # Zmienna do zliczania ilości wystąpień liczb ujemnych
  28. if j >= 4: # Problem rozwiązuj tylko w przypadku gdy są nie mniej niż 4 liczby
  29.     for number in apply_y: # Przejście po stablicowanych danych
  30.         if number < 0: negative_count += 1 # Jeżeli liczba ujemna to ją zliczaj
  31.         sum += number  # Oblicz sumę
  32.  
  33.  
  34. if negative_count > M:
  35.     print("Więcej liczb ujemnych niż M")
  36. elif negative_count < M:
  37.     print("Mniej liczb ujemnych niż M")
  38. else:
  39.     print("Tyle samo liczb ujemnych co M")
  40.  
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment