Найти - Пользователи
Полная версия: Как сделать, чтобы в конце кода суммировались сначала подразделы, которые вводил пользователь, а потом и сами разделы за формулой, что в скобках в конце? Помогите, пожайлуста, все никак не могу разобраться(
Начало » Python для новичков » Как сделать, чтобы в конце кода суммировались сначала подразделы, которые вводил пользователь, а потом и сами разделы за формулой, что в скобках в конце? Помогите, пожайлуста, все никак не могу разобраться(
1
Skiffich
 #!/usr/bin/python
# -*- coding: windows-1251 -*-
import os, sys
'''base = int(input('Enter the amount of funds allocated for the award:'))'''
number_main_section = int(input("Enter the number of partitions: "))
SECTION_NUMBER = 0
while SECTION_NUMBER < number_main_section:
    SECTION_NUMBER += 1
    def user_input_section():
        section_title = input("Enter a section name (A, B, C others): ")
        number_subdivisions = int(input("Enter the number of subsections of the section " +  str.upper(section_title) + ": "))
        type_of_kpi = int(input('Enter type of KPI (quantitative - 1; qualitative - 2): '))
        print("")
        return section_title, number_subdivisions, type_of_kpi
    user_input_section_list = user_input_section()
    CYCLE_NUMBER = 0
    while not (user_input_section_list[2] in [1, 2]):
        print("Wrong character entered!")
        user_input_section_list[2] = int(input('Enter type of KPI (quantitative - 1; qualitative - 2): '))
    if user_input_section_list[2] == 1:
        def user_input_of_section_quantitative_values(x, y):
            plan = int(input('Enter the target value (' + str.casefold(x) + str(y) + '): '))
            fact = int(input('Enter the actual target value (' + str.casefold(x) + str(y) + '): '))
            weight = int(input("Enter the weight in % (" + str.casefold(x) + str(y) + "): "))
            kpi = fact / plan * 100
            return plan, fact, weight, kpi
        while CYCLE_NUMBER < user_input_section_list[1]:
            CYCLE_NUMBER += 1
            user_input_of_section_values_list = user_input_of_section_quantitative_values(user_input_section_list[0], CYCLE_NUMBER)
            if user_input_of_section_values_list[1] > user_input_of_section_values_list[0] * 1.1:
                coefficient_value = 0
            elif user_input_of_section_values_list[0] * 1.02 < user_input_of_section_values_list[1] <= user_input_of_section_values_list[0] * 1.1:
                coefficient_value = user_input_of_section_values_list[2] * 0.8 / user_input_of_section_values_list[3]
            elif user_input_of_section_values_list[0] * 0.97 < user_input_of_section_values_list[1] <= user_input_of_section_values_list[0] * 1.02:
                coefficient_value = user_input_of_section_values_list[2] * 1.05 / user_input_of_section_values_list[3]
            else:
                coefficient_value = user_input_of_section_values_list[2] * 1.2 / user_input_of_section_values_list[3]
            if coefficient_value == 0:
                print("The value of the coefficient " + str(user_input_section_list[0]) + str(CYCLE_NUMBER) + ": 0 \n")
            else:
                print(str(round(coefficient_value, 3)) + "\n")
    elif user_input_section_list[2] == 2:
        def user_input_of_section_qualitative_values(x, y):
            weight = int(input("Enter the weight in % (" + str.casefold(x) + str(y) + "): "))
            kpi = int(input("Enter an assessment of the quality of the work performed (" + str.casefold(x) + str(y) + "): "))
            return weight, kpi
        while CYCLE_NUMBER < user_input_section_list[1]:
            CYCLE_NUMBER += 1
            user_input_of_section_values_list = user_input_of_section_qualitative_values(user_input_section_list[0], CYCLE_NUMBER)
            coefficient_value = (user_input_of_section_values_list[0] / 100) * user_input_of_section_values_list[1] / 3
            if coefficient_value == 0:
                print("The value of the coefficient " + str(user_input_section_list[0]) + str(CYCLE_NUMBER) + ": 0 \n")
            else:
                print(str(round(coefficient_value, 3)) + "\n")
    else:
        print('Wrong character entered!')
'''k = A * 0.4 + B * 0.4 + C * 0.2 [code python][code python][/code][/code]
premiya = base * k
print(str(premiya))'''
py.user.next
Что-то он как-то построен странновато. Лучше напиши задание без кода.
И функции никогда не определяются в блоках, только в глобальной области они должны одна за одной идти.
Skiffich
Задание заключается в написании калькулятора премий. Основная формула: База (Базовое количество денег выделенных на премию) * К. Мне нужно чтобы человек мог выбирать количество и имена разделов (А, В, С и т.д.) по которым в конце будет высчитываться К. Сами же разделы делятся на подразделы, их количество пользователь тоже должен задавать сам, а название будет таким же как и у раздела, только буквы будут маленькими и возле каждого подраздела стоит его номер (а1, а2, а3 и т.д.). Еще там есть КПЭ (Ключевые показатели эффективности), они бывают количественными и качественными. От них зависит вид формулы по которым считается коэффициент каждого подраздела. В моем коде (выше) есть все формулы.

Насчет функций, спасибо, буду знать!
py.user.next
Это начало
  
>>> def enter_sections():
...     out = []
...     while True:
...         section_name = input('Enter a section name: ')
...         if not section_name:
...             break
...         out.append(section_name)
...     return out
... 
>>> def enter_subsections():
...     out = []
...     while True:
...         subsection_name = input('Enter a subsection name: ')
...         if not subsection_name:
...             break
...         out.append(subsection_name)
...     return out
... 
>>> def enter_kpi_type():
...     out = None
...     while True:
...         kpi_type = input('Enter KPI type: ')
...         if not kpi_type:
...             break
...         out = kpi_type
...     return out
... 
>>> def count_bonus():
...     sections = enter_sections()
...     subsections = enter_subsections()
...     kpi_type = enter_kpi_type()
...     print(sections)
...     print(subsections)
...     print(kpi_type)
... 
>>> def main():
...     count_bonus()
... 
>>> main()
Enter a section name: A
Enter a section name: B
Enter a section name: C
Enter a section name: 
Enter a subsection name: a1
Enter a subsection name: a2
Enter a subsection name: a3
Enter a subsection name: b1
Enter a subsection name: b2
Enter a subsection name: b3
Enter a subsection name: c1
Enter a subsection name: c2
Enter a subsection name: c3
Enter a subsection name: 
Enter KPI type: 1
Enter KPI type: 
['A', 'B', 'C']
['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']
1
>>>
Определись с вводом сначала. Как вводишь данные, когда вводишь данные. Может быть, у тебя ввод раздела будет с вводом подразделов. Напиши эту процедуру саму по себе. Когда она готова и всё вводится, можно под эти введённые данные уже писать часть кода, которая вычисляет по этим данным значения.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB