Experiment 2 branch structure

The blog designed to provide for my little friends and additional reference, no time to tag specific analysis, hope you understanding

Experiment a currency conversion  

   Write a program between the yuan and the euro currency conversion, in which: fixed exchange rate between the yuan and the euro are: 1 euro = 7.88 yuan. Programs can receive input yuan or euros, converted to euros or yuan output. The use of RMB yuan, said the euro adoption EUR said there was no space between the sign and magnitude.

 Source

string=input("输入货币值")
unit=string[-3:]
money=eval(string[0:-3])
if(unit=="RMB" or "rmb"):
    print ('%.2f' %(money/7.88),"EUR")
elif(unit=="EUR"or "eur"):
    print(money*7.88,"RMB")

operation result

 

 

Experiment two  personal income tax calculation

Description: My personal income tax using "excess progressive tax rate" calculation method, the simplified formula is as follows:

     Tax = (salary deduction insurance personal income - tax exemption amount) * tax rate

Wherein the amount of a tax exempt 3500 yuan, tax payable according to the number of different, as shown below:

   ‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

level

Interval tax liability

tax rate

1‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

0 - 1500‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

3%‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

2‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

1500 - 4500‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

10%‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

3‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

4500 - 9000‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

20%‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

4‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

9000 - 35000‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

25%‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

5‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

35000 - 55000‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

30%‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

6‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

55000 - 80000‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

35%‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

7‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

More than 80,000

45%‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪‪‪‪‪‫‪

 Note: The "tax liability" as: personal salary deduction insurance income - tax exemption amount

Write a program to calculate personal income tax based on user input, the user input is a personal income payroll deduction insurance.

 User input is agreed to in RMB integer.

Source code (note add a comment)

i=input("请输入个人薪金扣险所得:")
i=eval(i)-3500
if(i>80000):
    i=i*0.45
elif(55000<i<=80000):
    i=i*0.35
elif(35000<i<=55000):
    i=i*0.3
elif(9000<i<=35000):
    i=i*0.25
elif(4500<i<=9000):
    i=i*0.2
elif(1500<i<=4500):
    i=i*0.1
elif(0<i<=1500):
    i=i*0.03

print("Taxable " , i)

  Operation results (FIG direct result taken)

 

 

Third experiment chickens and rabbits with cage   

Description: About 1,500 years ago, "Sun Tzu Suan Jing" on the records of this interesting question. The book is described:
Today there are pheasant rabbit with cage, there are thirty-five, at ninety four-legged, ask each rabbit pheasant geometry?
This means that the four sentences:
there are the same number of chickens rabbit in a cage, from the top, there are 35 heads, from the number below, there is 94 feet. Cage asked how many chickens and rabbits have?

Please compile a program, the user inputs two integers in the same line, represents the number of head and feet, the program calculates how many chickens have cages and rabbit, chicken and rabbit assumptions are normal, no disability. If no solution is output Data Error!

Source Code

= -1 In Flag 
head = the eval (INPUT ( " Please enter the number of head " )) 
Foot (INPUT (= the eval " Number Enter pin " )) 

for I in Range (head):
     for J in Range (head ):
         IF (I + J == head):
             IF ((. 4 + 2 * I * J) == Foot): 
                In Flag =. 1
                 Print ( " chickens " , J, " rabbit have " , I, " a " ) 

IF (In Flag < 0):
    print("Data Error!")

Operation results (FIG direct result taken)

 

 

Experiment 4 Statistics different number of characters   

User input from the keyboard line of characters, write a program that outputs the number of statistical and English characters, numbers, spaces, and other characters.

Source Codes (note add comments)

string=input("请输入一行字符")
english=0
num=0
space=0
other=0
for i in string:
    if('A'<i<'z'):
        english=english+1
    elif(i==" "):
        space=space+1
    elif('0'<i<'9'):
        numNUM + 1 =
     the else : 
        OTHER = OTHER + 1
 Print ( " English characters " , english)
 Print ( " digital " , NUM)
 Print ( " space " , Space)
 Print ( " other characters " , OTHER)

operation results (FIG direct result taken)

 

 

Experiment 5 guessing game   

Preset in the program integer between 0-9, allowing users to guess the number keypad to enter through, if the number is greater than the preset display "Unfortunately, too"; preset number is less than, shows "regret, too small "; and so on, until the number guessed, displays" forecast N times, you guessed ", where N is the number of user input digits!.

Source Codes (note add comments)

import random

num=random.randint(0,9)
i=0
while(True):
    i=i+1
    mynum=eval(input("Please input a num from zero to nine:"))
    if(mynum<num):
        print("small")
    elif(mynum>num):
        print("big")
    else:
        print("预测",i,"次,你猜中了!")
        break

Operation results (FIG direct result taken )

 

Guess you like

Origin www.cnblogs.com/cc123nice/p/11543732.html