Python Practice Example 1
title: There are four numbers: 1, 2, 3, 4, how many different and no repetition of the number of three digits? What's the number?
My Code: Python
#2017-7-20List_h= [1,2,3,4]list_c=[]list_u=[]n=0 forXinchList_h:list_c=list_h[:] List_c.remove (x) forYinchList_c:list_u=list_c[:] List_u.remove (y) forZinchlist_u:n+ = 1result= x * + y * 10 +ZPrint("Type%d:"% n, result)
Recommended code: Python
# !/usr/bin/python # -*-coding:utf-8-*- for< /span> i in range (1,5 for J in range (1,5 for k in range (1,5) : if (i! = k) and (i! = j)
and
(J!= K): print i,j,k
Combine the for loop and if statement into one sentence and print the result directly # !/usr/bin/env python # -*-coding:utf-8-*- = [1,2,3,4]list for if and and k! = i)]print (list)
Python Practice Example 2
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?
#2017-7-20#-*-coding:utf-8-*-profit= Int (Input ("Please enter the Profit value:")) List_profit= [1000000,600000,400000,200000,100000, 0]point= [0.01, 0.015, 0.03, 0.05, 0.075, 0.1]bonus=0 forXinchrange, Len (point):ifProfit >List_profit[x]: Bonus+ = (Profit-list_profit[x]) *Point[x] Profit=List_profit[x]Else: ContinuePrint(bonus)Python Practice Example 3
title: an Integer, which plus 100 is a complete square number, plus 168 is a complete square number, what is the number?
# 2017-07-20 # -*-coding:utf-8-*- for in range (2,85,2): = 168/ x if and and (x-y)% 2 = = 0: = (x + y)/2 = (XY)/2 = n * n-100 print(x)
Python Practice Example 4
Title: Enter a certain day of the year, judging the day is the first of the year?
#2017-7-20#-*-coding:utf-8-*- Year= Int (Input ("Please enter the year:") ) Month= Int (Input ("Please enter the month:")) Day= Int (Input ("Please enter the day:"))ifYear% 400 = = 0or(year% 100! = 0 andYear% 4 = =0): days= [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30]Else: Days= [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]which_day=0ifMonth >= 1 andMonth <= 12: forXinchRange (Month): Which_day+=Days[x] Which_day+= DayPrint("This was the %dth Day"%which_day)Else: Print('Error Month type')
Python (practice example)