SHARE
TWEET

Lesson5_1

Chernysh_1 Jan 22nd, 2020 (edited) 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. 1. Пользователь вводит данные о количестве предприятий, их наименования и
  3. прибыль за 4 квартала (т.е. 4 отдельных числа) для каждого предприятия..
  4. Программа должна определить среднюю прибыль (за год для всех предприятий) и
  5. вывести наименования предприятий, чья прибыль выше среднего и отдельно
  6. вывести наименования предприятий, чья прибыль ниже среднего.
  7. """
  8.  
  9.  
  10. QTY_PLANTS = (input('Please insert plants names via space: ')).split(' ')
  11. QTY =  len(QTY_PLANTS)
  12. BASE = {}
  13. for i in range(len(QTY_PLANTS)):
  14.   list1 = input(f'Please input EBIT for each quater via space. Plant {QTY_PLANTS[i]}:').split(' ')
  15.   list1 = [int(item) for item in list1]
  16.   BASE[QTY_PLANTS[i]] = list1
  17.  
  18.  
  19. AVG_VALUE = sum(map(sum, BASE.values())) / QTY
  20. LIST_LESS = []
  21. LIST_BIG = []
  22. for i in range(QTY):
  23.   if sum(BASE.get(QTY_PLANTS[i])) < AVG_VALUE:
  24.     LIST_LESS.append(QTY_PLANTS[i])
  25.   else:
  26.     LIST_BIG.append(QTY_PLANTS[i])
  27.  
  28. print(f'Меньше среднего: {LIST_LESS}')
  29. print(f'Больше среднего: {LIST_BIG}')
  30.  
  31.  
  32. # Решение через namedtuple
  33.  
  34. from collections import namedtuple
  35.  
  36. AVG_EBIT = 0
  37.  
  38. COMPANY_QTY = 4
  39. Company_info = namedtuple('company', 'name ebit')
  40. company_list = []
  41. for i in range(COMPANY_QTY):
  42.   name_c = input('company name: ')
  43.   total_year = [int(i) for i in input(f'please put an ebit for each quter via space for company {name_c}').split(' ')]
  44.   company = Company_info(name=name_c, ebit=sum(total_year))
  45.   company_list.append(company)
  46.  
  47. for i in company_list:
  48.   AVG_EBIT += i.ebit
  49. AVG_EBIT = AVG_EBIT/COMPANY_QTY
  50. print(f'Avarage EBIT of all companies: {AVG_EBIT}')
  51. print(f'Companies above avarage EBIT {[i for i in company_list if i.ebit > AVG_EBIT]}')
  52. print(f'Companies less avarage EBIT {[i for i in company_list if i.ebit < AVG_EBIT]}')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top