fifth assignment

Github project address: https://github.com/Moonlightlight/szys

PSP Form

Problem solving ideas:

1. Understand that the four operations refer to the four operations of addition, subtraction, multiplication and division.

2. Do the design first, the four operations need to have addition, subtraction, multiplication and division. Learn the libraries you need to use.

3. Understand and use tools such as performance analysis.

Design implementation process:

1. Randomly generate two integers between [1,100]

2. Randomly generate an operator (+,-,*,/)

3. Print two integers and an operator as one expression

4. The operation result of the user input formula

Key code:

while True:
    fh = random.randint(0, 3)
    n1 = random.randint(1, 100) #number 1
    n2 = random.randint(1, 100) #number 2
    jsz = 0 #calculated value
    if fh = = 0:
        #add jsz = n1 + n2
    elif fh == 1: #subtract
        n1,n2 = max(n1,n2),min(n1,n2)
        jsz = n1 - n2
    elif fh == 2: #phase Multiply
        jsz = n1 * n2
    elif fh == 3: #divide
        n1,n2 = max(n1,n2),min(n1,n2)
        while n1 % n2 != 0:
            n1 = random.randint(1, 100)
            n2 = random.randint(1, 100)
            n1,n2 = max(n1,n2),min(n1,n2)
        jsz = int(n1 / n2)
 
    print(n1, ysf[fh], n2, '= ', end='')

Screenshot of the program running:

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326041747&siteId=291194637