The website for Exercise 2:

www.runoob.com/python/pyth…


Example-2 The enterprise gives bonuses

Title: Bonuses paid by enterprises are based on profit commissions. When profit (I) is less than or equal to 100,000 yuan, 10% of bonus can be raised; If the profit is higher than 100,000 yuan, the part below 100,000 yuan will be 10% commission, and the part above 100,000 yuan will be 7.5% commission. Between 200,000 and 400,000 yuan, the part higher than 200,000 yuan, can be 5% commission; Between 400,000 and 600,000, the part higher than 400,000 yuan, can be 3% commission; When arrive between 600 thousand and 1 million, prep above 600 thousand yuan part, can commission 1.5%, prep above 1 million yuan when, the part of more than 1 million yuan presses 1% commission, input that month profit I from the keyboard, beg should extend bonus total amount?

Train of thought

This problem can be divided according to each bonus payment interval. First, two arrays are defined respectively. One array is the percentage of bonus in each interval, denoted as RAT. The other array is to record the upper boundary of each payment interval, indicating that when the upper boundary is exceeded, the upper boundary is directly multiplied by the proportion of the commission between the regions. For example, for the interval below 100,000 yuan, the upper boundary is 100,000, and after exceeding, the bonus between the regions is 100000*0.1.

And then we’re going to take the case where the profit is more than a million dollars, and we’re going to decrease the profit in turn, for each case.

Code implementation

def pay_award():
    profit = int(input(Net profit:) ARR = [1000000, 600000, 400000, 200000, 100000, 0] RAT = [0.01, 0.015, 0.03, 0.05, 0.075, 0.1] R = 0for idx in range(0, 6):
        if profit > arr[idx]:
            # Profit in the current range
            r += (profit - arr[idx]) * rat[idx]
            print('current award=', (profit - arr[idx]) * rat[idx])
            Reset the number of bonuses for the next interval
            profit = arr[idx]
    return r
Copy the code

Simple test example:

# Profit is 11,000Net profit :11000 Current Award = 1100.0 Award = 1100.0# Profit is 1.1 million (1.1 million)Net profit :1100000 Current award= 1000.0 Current award= 6000.0 Current award= 6000.0 Current award= 10000.0 Current award= 7500.0 current award= 10000.0 Award = 40500.0Copy the code

Source code at:

Github.com/ccc013/Code…

Or click on the original to view the source code.


Welcome to follow my wechat official account – Machine Learning and Computer Vision, or scan the qr code below, we can communicate, learn and progress together!

Past wonderful recommendation

Python-100 Exercise series
  • Python – 100 | exercises 01 & list comprehensions
Learning notes
  • Introduction to Machine Learning series 1 – An Overview of Machine learning
  • Getting to know GAN
  • GAN Learning Series 2: The Origin of GAN
  • [GAN Learning series 3] Image Restoration using Deep Learning and TensorFlow
Math study notes
  • Math Notes for programmers 1- Base conversion
  • Programmer’s Math Note 2– remainder
  • Mathematical Notes for Programmers 3– Iterative methods
Github projects & Resource tutorials recommended
  • [Github Project recommends] a better site for reading and finding papers
  • TensorFlow is now available in Chinese
  • Must-read AI and Deep learning blog
  • An easy-to-understand TensorFlow tutorial
  • Recommend some Python books and tutorials, both beginner and advanced!