实验二 计算器设计
实验报告模板如下:

学号 2020-2021-2 《Python程序设计》实验x报告

课程:《Python程序设计》
班级: 201933
姓名: 白晨阳
学号:20193314
实验教师:王志强
实验日期:2021年5月7日
必修/选修: 公选课

1.实验内容

设计并完成一个完整的应用程序,完成加减乘除模等运算,功能多多益善。

考核基本语法、判定语句、循环语句、逻辑运算等知识点

2. 实验过程及结果

在本次实验中我进行了十种运算
1.加法 2.减法 3.乘法 4.除法 5.三角函数
6.求指数 7.求模 8.求阶乘 9.求二元一次方程 10.求一元二次方程
以下原始代码:
`import math
PI = math.pi
none = 0
while none != 1:
print("1.加法 2.减法 3.乘法 4.除法 5.三角函数"
"6.求指数 7.求模 8.求阶乘 9.求二元一次方程 10.求一元二次方程 ")
mood = int(input("请输入你想运行的操作的编号:"))
if mood == 1:
a = float(input("请输入加数:"))
b = float(input("请输入被加的数:"))
c = a+b
print(c)
elif mood == 2:
a = float(input("请输入减数:"))
b = float(input("请输入被被数:"))
c = a-b
print(c)
elif mood == 3:
a = float(input("请输入乘数:"))
b = float(input("请输入被乘的数:"))
c = ab
print(c)
elif mood == 4:
print("1.除法2.求整3.求余")
way = int(input("请输入要进行操作"))
if way == 1:
a = float(input("请输入除数:"))
b = float(input("请输入被除数:"))
c = a/b
print(c)
elif way == 2:
a = float(input("请输入除数:"))
b = float(input("请输入被除数:"))
c = int(a//b)
print(c)
elif way == 3:
a = float(input("请输入除数:"))
b = float(input("请输入被除数:"))
c = a % b
print(c)
else:
print("输入错误")
elif mood == 5:
print("1.sin 2.cos 3.tan 4.arcsin 5.arccso 6.arctan")
way = int(input("请输如要进行的操作:"))
if way == 1:
a = float(input("请输如要执行的数(角度)"))
b = math.sin((a/180)
PI)
print(b)
elif way == 2:
a = float(input("请输如要执行的数(角度)"))
b = math.cos((a/180)PI)
print(b)
elif way == 3:
a = float(input("请输如要执行的数(角度)"))
b = math.tan((a/180)
PI)
print(b)
elif way == 4:
a = float(input("请输如要执行的数"))
b = math.asin(a)

        print((b/PI)*180)
    elif way == 5:
        a = float(input("请输如要执行的数"))
        b = math.acos((a/PI)*180)
        print((b/PI)*180)
    elif way == 6:
        a = float(input("请输如要执行的数"))
        b = math.atan((a/PI)*180)
        print((b/PI)*180)
    else:
        print("输入错误")
elif mood == 6:
    a = float(input("请输入底数:"))
    b = float(input("请输入指数:"))
    c = a**b
    print(c)
elif mood == 7:
    a = float(input("请输入值:"))
    b = float(input("请输入模:"))
    c = a%b
    print(c)
elif mood == 8:
    a = int(input("请输如要求的数"))
    if a <= 0:
        print("输入错误")
    b = 1
    for i in range(1, a+1):
        b = b*i
    print(b)
elif mood == 9:
    print("输入形如ax^2+bx+c=0中的a,b,c")
    a = float(input("请输入a:"))
    b = float(input("请输入b:"))
    c = float(input("请输入c:"))
    if b**2-4*a*c == 0:
        x1 = -(b/2*a)
        x2 = -(b/2*a)
        print("该方程的解为:x1=", x1,"x2=", x2)
    elif b**2-4*a*c < 0:
        print("该方程无实数解")
    else:
        x1 = (-b + (b**2-4*a*c)**0.5)/2*a
        x2 = (-b - (b**2-4*a*c)**0.5)/2*a
        print("x1=" + x1+"x2=" + x2)
elif mood == 10:
    print("输入形如a1x+b1y=c1,a2x+b2y=c2的函数中的a1,b1,c1,a2,b2,c2")
    a1 = float(input("请输入a1:"))
    b1 = float(input("请输入b1:"))
    c1 = float(input("请输入c1:"))
    a2 = float(input("请输入a2:"))
    b2 = float(input("请输入b2:"))
    c2 = float(input("请输入c2:"))
    x = (c1*b2-c2*b1)/(a1*b2-a2*b1)
    y = (c2*a1-c1*a2) / (a1*b2-a2*b1)
    print("x=", x, "y=", y)
else:
    print("输入错误")
none = int(input("继续输出1以外的数,退出输出1"))

`
结果:1.加法

2.减法

3.乘法

4.除法

5.三角函数"

6.求指数

7.求模

8.求阶乘

9.求二元一次方程

10.求一元二次方程

3. 实验过程中遇到的问题和解决过程

  • 问题1:一元二次方程的求解问题
  • 问题1解决方案:找书回忆
  • 问题2:在阶乘中出现部分错误
  • 问题2解决方案:发现是少了个:

其他(感悟、思考等)

通过本次实验,让我对if等有了更加深刻的了解,并对编写代码更加熟练。实验过程中确实遇到了许多问题,与C语言相比较,python的编译更加灵活,格式也没有像C语言一样必须任何一处标点都不能有错误。但python对if的条件语句更加苛刻,这次实验小有感悟。

posted on 2021-05-07 13:40  woaiwolai  阅读(143)  评论(0编辑  收藏  举报