Advertisement
kozhilya

Untitled

Dec 7th, 2022
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import random
  2.  
  3. A = list()
  4.  
  5. # n = int(input("Введите n: "))
  6. n = 10
  7.  
  8. print("Массив:")
  9. for i in range(n):
  10.     # Получить случайное значение от -10 до 10
  11.     A.append(random.random() * 20 - 10)
  12.     print("{:8.3f}".format(A[i]))
  13.  
  14. massiv_abs = list(map(abs, A))
  15. min_abs = min(massiv_abs)
  16. min_i = massiv_abs.index(min_abs)
  17. print("Минимальное значение по модулю: A[{}] = {:.3f}".format(min_i, min_abs))
  18.  
  19.  
  20. A_is_negative = list(map(lambda v: v < 0, A))
  21. i_first_negative = A_is_negative.index(True)
  22. summa = sum(A[(i_first_negative+1):])
  23. print("Сумма элементов после первого отрицательного: {:.3f}".format(summa))
  24.  
  25. exit()
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement