20194306 Experiment 2 "Python Programming" Experiment Report

Student ID 2019-2020-2 "Python Programming" Experiment x Report

Course: "Python Programming"
Class: 1943
Name: Chen Wei
Student ID: 20194306
Experimental Teacher: Wang Zhiqiang
Experiment Date: April 20, 2020
Compulsory / Elective: Public Elective Course

1. Experimental content

· Design and complete a complete application program to complete operations such as addition, subtraction, multiplication and division, and more functions.

· Appraisal of knowledge points such as basic grammar, judgment statements, loop statements, logical operations, etc.

2. Experimental process and results

def Sum(a,b):
    print("a+b=",a+b)
def Subtraction(a,b):
    print("a-b=",a-b)
def Multiplication(a,b):
    print("a*b=:",a*b)
def Division(a,b):
    if b != 0:
        print("a/b=:",a/b)
    else:
        print("无法计算!")
def Mo(a,b):
    print("两数求模为",a%b)
def Mifang(a,b):
    print("a^b=",a**b)

print("启动计算器。")
while True:
    print("加法请按1,减法请按2,乘法请按3,除法请按4,求模请按5,求幂请按6,退出计算器请按7")
    print("请选择:")
    x = int(input())
    if x == 7:
        print("计算器关闭。")
        break
    if x == 6:
        a = int(input("请输入一个数:"))
        b = int(input("请输入一个数:"))
        print(Mifang(a,b))
    a = float(input("请输入一个数:"))
    b = float(input("请输入一个数:"))
    if x == 1:
        print(Sum(a,b))
    elif x == 2:
        print(Subtraction(a,b))
    elif x == 3:
        print(Multiplication(a,b))
    elif x == 4:
        print(Division(a,b))
    elif x == 5:
        print(Mo(a,b))

3. Problems encountered during the experiment and the resolution process

  • Question 1: Enter a and b before closing the calculator
  • Solution to Problem 1: Move the code related to the closed calculator forward.
  • Problem 2: Program error when performing power calculation
  • Problem 2 solution: Float type cannot be used for power calculation, the relevant code for power calculation is moved forward, a and b are changed to int type, and the continue function is added

Others (sentiment, thinking, etc.)

Through this experiment, the content learned during this period of time is consolidated, such as the basic knowledge of python, judgment statements, loop statements, logical operations and other knowledge points

Guess you like

Origin www.cnblogs.com/cw4306/p/12740021.html