1_rinkana

Лабораторна робота №1 "розгалуж цикли"

Sep 27th, 2023 (edited)
1,559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1. def main():
  2.     min_function()
  3.     y_function()
  4.     sum_function()
  5.     sum_of_multiplication()
  6.     tabulation()
  7.     print(find_index_of_last_7())
  8.     count_negative_numbers()
  9.  
  10. def min_function():
  11.     print("Введите x, y, z через пробел:")
  12.     x, y, z = map(int, input().split())
  13.     minimum = x if x < y and x < z else (y if y < z else z)
  14.     print(f"Min of x, y, z = {minimum}\n")
  15.  
  16. def y_function():
  17.     print("Введіть у з клавіатури:")
  18.     y = int(input())
  19.     y_result = 5 * y if y >= 0 else 0
  20.     print(f"y = {y_result}\n")
  21.  
  22. def sum_function():
  23.     print("Введите n")
  24.     n = int(input())
  25.     total_sum = 0
  26.     for i in range(1, n + 1):
  27.         total_sum += i / (i + 3)
  28.     print(f"Сумма = {total_sum}\n")
  29.  
  30. def sum_of_multiplication():
  31.     print("Введите n")
  32.     n = int(input())
  33.     total_sum = 1
  34.     for i in range(1, n + 1):
  35.         total_sum *= (i + 3) / (factorial(i) + 2)
  36.     print(f"Сумма при умножении = {total_sum}\n")
  37.  
  38. def factorial(num):
  39.     result = 1
  40.     for i in range(1, num + 1):
  41.         result *= i
  42.     return result
  43.  
  44. def tabulation():
  45.     start_x = -3.0
  46.     end_x = 3.0
  47.     step = 0.5
  48.  
  49.     print("x\t  y")
  50.     print("--------------")
  51.  
  52.     x = start_x
  53.     while x <= end_x:
  54.         y = x * x - 1
  55.         print(f"{x}\t{y}")
  56.         x += step
  57.     print()
  58.  
  59. def find_index_of_last_7():
  60.     print("Введите n")
  61.     n = input()
  62.     reversed_str = n[::-1]
  63.  
  64.     for index, char in enumerate(reversed_str):
  65.         if char == '7':
  66.             return f"Порядковый номер последней цифры 7 с конца: {index}"
  67.  
  68.     return "Цифра 7 не найдена"
  69.  
  70. def count_negative_numbers():
  71.     print("Введите n")
  72.     n = int(input())
  73.  
  74.     negative_count = 0
  75.  
  76.     for i in range(1, n + 1):
  77.         number = int(input(f"Введите число a{i}: "))
  78.         if number < 0:
  79.             negative_count += 1
  80.  
  81.     print(f"Количество отрицательных чисел в последовательности: {negative_count}")
  82.  
  83.  
  84. if __name__ == "__main__":
  85.     main()
Advertisement
Add Comment
Please, Sign In to add comment