20192416 "Python Programming" Experiment 2 Report

20192416 "Python Programming" Experiment 2 Report

Course: "Python Programming"
Class: 1924
Name:
Anonymous who did not wish to be named Student ID: 20192416
Experimental Teacher: Teacher Wang Zhiqiang
Experimental Date: April 11, 2020
Compulsory / Elective: Public Elective

1. Experimental content

  • Design and complete a complete application program, complete operations such as addition, subtraction, multiplication and division, and more functions.
  • Examine the knowledge points of basic grammar, judgment statements, loop statements, logical operations, etc.

2. Experimental process and results

After a period of hard work, a relatively simple calculator was completed. Can add, subtract, multiply, divide, modulo, trigonometric function, square root. Errors are reported for some cases that do not meet the specifications, which improves the user ( only me ) experience.

import math
print("这是一个巨菜的计算器:")
a = int (input("输入0:结束    输入1:加   输入2:减   输入3:乘   输入4:除   输入5:模   输入6:三角函数   输入7:求平方根\n"))
if a==0:
    print("结束")
elif a==1:
    print("输入相加的数,最后一个数为0时结束")
    b = float(input())
    c=0
    while(b!=0):
        c=c+b
        b = float(input())
    print("他们的和为",c)
elif(a==2):
    print("先输入被减数,依次输入减数,最后一个数为0时结束")
    b = float(input())
    c=b*2
    while(b!=0):
        c=c-b
        b = float(input())
    print("结果为",c)
elif a==3:
    print("输入相乘的数,最后一个数为1时结束")
    b = float(input())
    c=1
    while(b!=1):
        c=c*b
        b = float(input())
    print("他们的积为",c)
elif a==4:
    print("先输入被除数,依次输入除数,最后一个数为1时结束")
    b = float(input())
    c = b*b
    while(b!=1 and b!=0):
        c=c/b
        b = float(input())
    else:
        print("error")
    print("他们的结果为",c)
elif a==5:
    print("分别输入a和b,将输出结果a%b")
    b=float(input())
    c=float(input())
    print(b,"%",c,"=",b%c)
elif a==6:
    print("下面进行三角函数的计算")
    a = float (input("输入1:sin   输入2:cos   输入3:tan   "))
    b = float (input("输入要进行计算的角度:"))
    c = b/180*math.pi
    if a==1:
        print("sin(",b,"°)=",round(math.sin(c),3))
    if a==2:
        print("sin(",b,"°)=",round(math.cos(c),3))
    if a==3:
        print("sin(",b,"°)=",round(math.tan(c),3))
elif a==7:
    b= float(input("输入要计算的数:"))
    if (b>=0):
        print("结果为:",math.sqrt(b))
    else:
        print("error")

3. Problems encountered during the experiment and the resolution process

  • Question 1: I do n’t know how to express the root and trigonometric functions in mathematics.
  • Solution for Problem 1: Various special operators are loaded through import math. Such as: math.sqrt (), math.sin (), math.pi, etc.
  • Question 2: There are too many reserved bits in the trigonometric function, which is not good-looking.
  • Solution for Problem 2: Round (a, b) a is used as the number to be processed, and b is the reserved valid number.

Perception

This experiment is relatively smooth, but because of limited ability, it is impossible to make more complex mixed operations (the poverty of knowledge limits my imagination), which is a pity. I hope to gain stronger programming skills and write better code in the next study.

Guess you like

Origin www.cnblogs.com/hantaku/p/12677889.html