100 python hands-on small programs -- a shortcut for python to get started quickly

Address: https://www.runoob.com/python/python-100-examples.html T1: Topic: there are four numbers: 1, 2, 3 and 4. How many three digits that are diff...

Address: https://www.runoob.com/python/python-100-examples.html

T1: Topic: there are four numbers: 1, 2, 3 and 4. How many three digits that are different from each other and have no repetition? How many are each?
Program analysis: the numbers that can be filled in hundreds, tens and ones are all 1, 2, 3 and 4. Make up all permutations before removing the ones that do not meet the conditions.

import numpy as np data = np.array(range(1,5)) print(data) list=[] for i in data: print(i) for j in data: for t in data: if (i!=j)&(j!=t)&(t!=i):#I didn't think about this when I was doing the questions list.append(i*100 +10*j +t) print(list)

Note: if (I! = J) & (J! = t) & (t! = I): ා not considered when doing the question

T2: Topic: the bonus paid by the enterprise is based on the profit commission. If the profit (I) is less than or equal to RMB 100000, the bonus can be increased by 10%; if the profit is higher than RMB 100000, the part lower than RMB 100000 will be increased by 10%; if the profit is higher than RMB 100000, the bonus can be increased by 7.5%; if the profit is between RMB 200000 and RMB 400000, the bonus can be increased by 5%; if the profit is between RMB 400000 and RMB 600000, the bonus can be increased by 3%; if the profit is between RMB 600000 and RMB 1000000, the bonus can be increased by 3%; if the profit is higher than RMB 600000 For the part above 1 million yuan, 1% commission will be applied for the part above 1 million yuan. Input the profit I of the month from the keyboard, and calculate the total amount of bonus to be paid?
Program analysis: please use the number axis to divide and locate. Pay attention to defining bonus as growth integer.

#!/usr/bin/python #coding:utf-8 data = int(input()) print(type(data)) if data <= 100000: data = data * (1 + 0.1) if (data > 100000) & (data <= 200000): data = 100000 * (1 + 0.1) + (data - 100000) * (1 + 0.75) if (data > 200000) & (data <= 400000): data = 100000 * (1 + 0.1) + 100000 * (1 + 0.75) + (data - 200000) * (1 + 0.05) if (data > 400000) & (data <= 600000): data = 100000 * (1 + 0.1) + 100000 * (1 + 0.75) + 200000 * (1 + 0.05) + (data - 400000) * (1 + 0.03) if (data > 600000) & (data <= 1000000): data = 100000 * (1 + 0.1) + 100000 * (1 + 0.75) + 200000 * (1 + 0.05) + 200000 * (1 + 0.03) + (data - 600000) * ( 1 + 0.015) if data > 1000000: data = 100000 * (1 + 0.1) + 100000 * (1 + 0.75) + 200000 * (1 + 0.05) + 200000 * (1 + 0.03) + 400000 * ( 1 + 0.015) + (data - 1000000) * (1 + 0.01) print(data)

The standard answer is better:

#!/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

Note: data = input() is str, and int needs to be converted to integer

6 November 2019, 15:38 | Views: 2466

Add new comment

For adding a comment, please log in
or create account

0 comments