This article summarizes the ways in which if is written in the Python learning process
Python instance learning small problems encountered, I change the topic need to display the results of each file, you can use the list and if statement to complete, the article finally is the original topic and the answer
One, if the way
A, procedures
#!/usr/bin/python
#-*-Coding:utf-8-*-
i = 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 = 0
For IDX in range (0, 6):
If i > Arr[idx]:
R + = (I-arr[idx]) * RAT[IDX]
If arr[idx] = = 0:
Print (' <100000 ', ' gears ', (I-arr[idx]) * RAT[IDX])
Else
Print (Arr[idx], ' gears ', (I-arr[idx]) * RAT[IDX])
i = Arr[idx]
Print (' Total bonus: ', R)
D:\PythonScript\python\python.exe d:/pythonscript/456
Net profit: 1100000
1000000 Gear 1000.0
600000 Gear 6000.0
400000 Gear 6000.0
200000 Gear 10000.0
100000 Gear 7500.0
<100000 file 10000.0
Total Bonuses: 40500.0
Process finished with exit code 0
B, procedures
#!/usr/bin/python
#-*-Coding:utf-8-*-
i = 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 = 0
For IDX in range (0, 6):
If i > Arr[idx]:
R + = (I-arr[idx]) * RAT[IDX]
If arr[idx] = = 0:
Print (' <100000 ', ' gears ', (I-arr[idx]) * RAT[IDX])
Else
Print (Arr[idx], ' gears ', (I-arr[idx]) * RAT[IDX])
i = Arr[idx]
Print (' Total bonus: ', R)
B. Results
D:\PythonScript\python\python.exe d:/pythonscript/456
Net profit: 1100000
1100000 Gear 1000.0
1000000 Gear 6000.0
600000 Gear 6000.0
400000 Gear 10000.0
200000 Gear 7500.0
<100000 file 10000.0
Total Bonuses: 40500.0
Process finished with exit code 0
C, procedures
#!/usr/bin/python
#-*-Coding:utf-8-*-
i = 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 = 0
For IDX in range (0, 6):
If i > Arr[idx]:
R + = (I-arr[idx]) * RAT[IDX]
Print (Arr[idx] if arr[idx]>0 else ' <100000 ', ' stalls ', (I-ARR[IDX]) * RAT[IDX])
i = Arr[idx]
Print (' Total bonus: ', R)
C. Results
D:\PythonScript\python\python.exe d:/pythonscript/456
Net profit: 1100000
1000000 Gear 1000.0
600000 Gear 6000.0
400000 Gear 6000.0
200000 Gear 10000.0
100000 Gear 7500.0
<100000 file 10000.0
Total Bonuses: 40500.0
Process finished with exit code 0
Second, the way of the list
Program
#!/usr/bin/python
#-*-Coding:utf-8-*-
i = Int (input (' Net profit: '))
arr = [1000000,600000,400000,200000,100000,0]
Rat = [0.01,0.015,0.03,0.05,0.075,0.1]
FFF = [' Sixth gear ', ' V ', ' IV ', ' third gear ', ' second gear ', ' first gear ']
R = 0
For IDX in range (0,6):
If I>ARR[IDX]:
r+= (I-arr[idx]) *rat[idx]
Print (Fff[idx], (I-arr[idx]) *rat[idx])
I=ARR[IDX]
Print (' Total bonus: ', R)
Results
D:\PythonScript\python\python.exe d:/pythonscript/123.py
Net profit: 1100000
Six 1000.0
Document 6000.0
IV 6000.0
Third Gear 10000.0
Second Gear 7500.0
First Gear 10000.0
Total Bonus: 40500.0
Process finished with exit code 0
Ii. Original topics and solutions
Title: The bonuses awarded by the Enterprise are based on the profit commission. Profit (I) less than or equal to $100,000, the bonus can be raised by 10%, the profit is higher than $100,000, less than $200,000, the portion of less than 100,000 yuan by 10% commission, higher than the portion of 100,000 yuan, a commission of 7.5%, 200,000 to 400,000, higher than 200,000 yuan, can commission 5% ; Between 400,000 and 600,000 is higher than the portion of 400,000 yuan, can commission 3%, 600,000 to 1 million, higher than 600,000 yuan portion, can commission 1.5%, higher than 1 million yuan, the portion of more than 1 million yuan by 1% Commission, from the keyboard input month profit I, the total bonus should be issued?
Program Analysis: Please use the axis to demarcation, positioning. Note that the bonus definition should be defined as the growth integral type.
Program Source code:
Instance (Python 2.0+)
#!/usr/bin/python
#-*-Coding:utf-8-*-
i = Int (raw_input (' Net profit: '))
arr = [1000000,600000,400000,200000,100000,0]
Rat = [0.01,0.015,0.03,0.05,0.075,0.1]r = 0
For IDX in range (0,6):
If I>ARR[IDX]:
r+= (I-arr[idx]) *rat[idx]
Print (I-arr[idx]) *rat[idx]
I=arr[idx]print R
The result of the above example output is:
Net profit: 120000
1500.0
10000.0
11500.0