登录后查看本帖详细内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
4.13: import sys status= eval(input('(0-singlefiler,1-married jointly,\n'+ '2-married separately,3-head of household)\n'+ 'enter the filing status:')) income = eval(input('enter thetaxable income:')) tax=0 if status == 0: if income <= 8350: tax = income * 0.10 elif income <33950 : tax=8350*0.10+(income-8350)*0.15 elif income <82250 : tax=8350*0.10+(33950-8350)*0.15+(income-33950)*0.25 elif income <171550: tax=8350*0.10+(33950-8350)*0.15+(82250-33950)*0.25+\ (income-82250)*0.28 elif income <372950 : tax=8350*0.10+(33950-8350)*0.15+(82250-33950)*0.25+\ (171550-82250)*0.28+(income-171550)*0.33 else: tax=8350*0.10+(33950-8350)*0.15+(82250-33950)*0.25+\ (171550-82250)*0.28+(372950-171550)*0.33+\ (income-372950)*0.35 elif status==1: if income <= 16700: tax = income * 0.10 elif income <67900 : tax=16700*0.10+(income-16700)*0.15 elif income <137050 : tax=16700*0.10+(67900-16700)*0.15+(income-67900)*0.25 elif income <208805: tax=16700*0.10+(67900-16700)*0.15+(137050-67900)*0.25+\ (income-137050)*0.28 elif income <372950 : tax=16700*0.10+(67900-16700)*0.15+(137050-67900)*0.25+\ (208805-137050)*0.28+(income-208805)*0.33 else: 16700*0.10+(67900-16700)*0.15+(137050-67900)*0.25+\ (208805-137050)*0.28+(372950-208805)*0.33+\ (income-372950)*0.35 elif status == 2: if income <= 8350: tax = income * 0.10 elif income <33950 : tax=8350*0.10+(income-8350)*0.15 elif income <68525 : tax=8350*0.10+(33950-8350)*0.15+(income-33950)*0.25 elif income <104425: tax=8350*0.10+(33950-8350)*0.15+(68525-33950)*0.25+\ (income-68525)*0.28 elif income <186475 : tax=8350*0.10+(33950-8350)*0.15+(68525-33950)*0.25+\ (104425-68525)*0.28+(income-104425)*0.33 else: 8350*0.10+(33950-8350)*0.15+(68525-33950)*0.25+\ (104425-68525)*0.28+(186475-104425)*0.33+\ (income-186475)*0.35 elif status == 3: if income <= 11950: tax = income * 0.10 elif income <45500 : tax=11950*0.10+(income-11950)*0.15 elif income <117450 : tax=11950*0.10+(45500-11950)*0.15+(income-45500)*0.25 elif income <190200: tax=11950*0.10+(45500-11950)*0.15+(117450-45500)*0.25+\ (income-117450)*0.28 elif income <372950 : tax=11950*0.10+(45500-11950)*0.15+(117450-45500)*0.25+\ (190200-117450)*0.28+(income-190200)*0.33 else: 11950*0.10+(45500-11950)*0.15+(117450-45500)*0.25+\ (190200-117450)*0.28+(372950-190200)*0.33+\ (income-372950)*0.35 else: print('error') sys.exit print('tax is ',format(tax,'.2f')) 4.14: import random coin=random.randint(0,1) number=eval(input('正面为1,背面为0,你猜是?')) print( coin==number if coin == number else coin==number) 4.15: import random guess=eval(input('你猜中奖号码是多少?')) number=random.randint(0,999) guess1=guess // 100 guess2=guess // 10 % 10 guess3=guess % 10 number1=number // 100 number2=number // 100 % 10 number3=number % 10 number_list=[number1,number2,number3] if guess==number: print('bingo!you win all 10000$') elif (number1==guess1 or number1==guess2 or number1==guess3) and\ ((number2==guess1 or number2==guess2or number2==guess3) and\ (number3==guess1 or number3==guess2or number3==guess3)) : print('match all number,you win 3000$') elif ((guess1 in number_list) and (guess2 notin number_list) and (guess3 notin number_list)) or\ ((guess2 in number_list) and (guess1 notin number_list) and (guess3 notin number_list)) or\ ((guess3 in number_list) and (guess1 notin number_list) and (guess2 notin number_list)): print('you just match one number,you win 1000$') else: print('sorry,you guess nnumber is wrong ,no money') print(guess,number) 4.16: import random number=random.randint(ord('A'),ord('Z')) print(chr(number)) 4.17: import random computer=random.randint(0,2) people=eval(input('scissor(0),rock(1),paper(2):')) if people==computer: print('the computer is '+str(computer)+'youare '+str(people)+'too.'+'it is a draw') elif computer==0and people==1: print('the computer is '+str(computer)+'youare '+str(people)+'you win !') elif computer==0and people==2: print('the computer is '+str(computer)+'youare '+str(people)+'the computer win !') elif computer==1and people==0: print('the computer is '+str(computer)+'youare '+str(people)+'the computer win !') elif computer==1and people==2: print('the computer is '+str(computer)+'youare '+str(people)+'you win !') elif computer==2and people==0: print('the computer is '+str(computer)+'youare '+str(people)+'you win !') elif computer==2and people==1: print('the computer is '+str(computer)+'youare '+str(people)+'the computer win !') else: print('input eorro') 4.18: rate=eval(input('enter theexchange rate from dollars to RMB:')) number=eval(input('enter 0 toconvert dollars to RMB and 1 vice versa:')) if number == 0: dollars=eval(input('enter the dollars amount:')) rmb=dollars*rate print(str(dollars)+'dollarsis',format(rmb,'.2f')+'yuan') elif number==1: rmb=eval(input('enter the rmb amount:')) dollars=rmb/rate print(str(rmb)+'rmb is',format(dollars,'.2f')+'dollars') else: print('incorrect input') 4.19: side1,side2,side3=eval(input('输入三角形三条边长:')) if side1+side2>side3 and side2+side3>side1 and side1+side3>side2: perimeter=side1+side2+side3 print('the perimeter is '+str(perimeter)) else: print('the input is invalid')
|