Python Case 002 (Gets the and of different data ranges) __python

Source: Internet
Author: User

The topic content comes from the network, joins the individual understanding the process, and reviews


#! /usr/bin/python #-*-Coding:utf-8-*-"" Request: Title: Corporate bonuses are based on profits. Profit (I) is less than or equal to 100,000 yuan, the bonus can be mentioned 10%, the profit is higher than 100,000 yuan, less than 200,000 yuan, less than 100,000 yuan part by 10% commission, higher than 100,000 yuan portion, can commission 7.5%, 200,000 to 400,000 when, higher than 200,000 yuan of the portion, can commission 5%
400,000 to 600,000 when the portion of more than 400,000 yuan, can be a commission of 3%, 600,000 to 1 million when, higher than 600,000 yuan, can be a commission of 1.5%, more than 1 million yuan, more than 1 million yuan in the portion of 1% commission, from the keyboard input month profit I, the total number of bonuses should be issued. "" "#define Two lists # method 1 revenue=[1000000,600000,400000,200000,100000,0] deduct=[ 0.01,0.015,0.03,0.05,0.075,0.1] Profit = Int (raw_input ("Please enter the Revenue:") earning = 0 to X in range (Len (deduc 

T): If profit > Revenue[x]: earning+= (profit-revenue[x]) *deduct[x] profit=revenue[x] Print earning #method 2, find the data nprofit = Int (raw_input ("Please enter the Revenue:") for each interval nrevenue=[1000000,600000,400000,200000,10000 0,0] ndeduct=[0.01,0.015,0.03,0.05,0.075,0.1] # define an A new list to put this data in nearning = 0 Newprofit =[] for x i
        N Range (len (nrevenue)): If Nprofit > nrevenue[x]: nearning = (nprofit-nrevenue[x]) # Calculate data values for each interval segment Nprofit = NrevenUe[x] Newprofit.append (nearning) else:newprofit.append (0) # fills the default value with zero, multiplies without affecting the result # try to using LA MBDA Zipdata = Zip (newprofit,ndeduct) print zipdata trynew = SUM (Map (Lambda (x,y): X*y,zipdata)) # x, Y is a tuple in zipdata

Tuple Print Trynew # This place is easy to confuse with map reduce in Spark #method 3, consider using a list to push to.  # Result: ' "Please enter the revenue:100000000 1029500.0 please enter the revenue:100000000 [(99000000, 0.01), (400000,





 0.015), (200000, 0.03), (200000, 0.05), (100000, 0.075), (100000, 0.1)] 1029500.0 "" "


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.