Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- # Definicja funkcji y
- def y(x):
- if (x > -2 and x < 2) and x != -1:
- return math.log(4 - x**2) / (1 + x)
- elif x <= -2 or x >= 2:
- return (4 - x**2) / (1 + x)
- else:
- return 4
- # Jednowymiara macierz wejściowa
- input_data = [-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13]
- # Stablicować funkcję y
- apply_y = []
- for x in input_data:
- apply_y.append(y(x))
- M = 4 # Ile liczb ujemnych chcemy mieć
- j = len(input_data) # Ilość danych liczb
- # Zadanie
- sum = 0 # Zmienna do zliczania sumy
- negative_count = 0 # Zmienna do zliczania ilości wystąpień liczb ujemnych
- if j >= 4: # Problem rozwiązuj tylko w przypadku gdy są nie mniej niż 4 liczby
- for number in apply_y: # Przejście po stablicowanych danych
- if number < 0: negative_count += 1 # Jeżeli liczba ujemna to ją zliczaj
- sum += number # Oblicz sumę
- if negative_count > M:
- print("Więcej liczb ujemnych niż M")
- elif negative_count < M:
- print("Mniej liczb ujemnych niż M")
- else:
- print("Tyle samo liczb ujemnych co M")
Advertisement
Add Comment
Please, Sign In to add comment