20191108 实验二《Python程序设计》实验报告

20191108 2019-2020-2 《Python程序设计》实验二报告

课程:《Python程序设计》
班级: 1911
姓名: 朱家婧
学号:20191108
实验教师:王志强
实验日期:2020年4月X12日
必修/选修: 公选课

1.实验内容

  • 设计并完成一个完整的应用程序,完成加减乘除模等运算,功能多多益善。
  • 考核基本语法、判定语句、循环语句、逻辑运算等知识点

2. 实验过程及结果

第一步是加减乘除模:

import math
yunsuan=str(input("输入运算方式:"))
if yunsuan=="+"or yunsuan=="-"or yunsuan=="/"or yunsuan=="%":
    print("依次输入两个运算数字:")
    a=float(input())
    b=float(input())
    if yunsuan=="+":
        print(a+b)
    elif yunsuan=="-":
        print(a-b)
    elif yunsuan=="*":
        print(a*b)
    elif yunsuan=="/":
        print(a/b)
    elif yunsuan=="%":
        print(a%b)

第二步是三角函数(包括sin cos tan cot sec csc):

elif yunsuan=="sin" or yunsuan=="cos"or yunsuan=="tan"or yunsuan=="cot"or yunsuan=="sec"or yunsuan=="csc":
    print("输入角度(弧度制):")
    a=float(input())
    if yunsuan=="sin":
        print(math.sin(a))
    elif yunsuan=="cos":
        print(math.cos(a))
    elif yunsuan=="tan":
        print(math.tan(a))
    elif yunsuan=="cot":
        print(1/math.tan(a))
    elif yunsuan=="sec":
        print(1/math.cos(a))
    elif yunsuan=="csc":
        print(1/math.sin(a))

第三步是n次方和开n次根:

elif yunsuan=="指数":
    a=float(input("输入底数:"))
    b=float(input("输入指数:"))
    print(math.pow(a,b))

第四步是阶乘:

elif yunsuan=="阶乘":
    a=float(input("输入数字:"))
    print(math.factorial(a))

第五步是多数字进行连续加减乘除:

因为第一步只能进行二元运算,所以对其作出改进:

elif yunsuan=="多数字运算":
    a = int(input("数字个数:"))
    print("请依次输入数字:")
    b=[]
    for i in range(a):
        b.append(float(input()))
    x=str(input("输入运算符:"))
    y=0
    z=1
    if x=="+":
        for i in range(a):
            y=y+b[i]
        print(y)
    if x=="-":
        for i in range(a):
            y=y-b[i]
        print(y)
    if x=="*":
        for i in range(a):
            z=z*b[i]
        print(z)
    if x=="/":
        for i in range(a):
            z=z/b[i]
        print(z)

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

  • 问题1:if yunsuan=="+"or"-"or"/"or"%"导致只能执行这个if的条件
  • 问题1解决方案:改为if yunsuan"+"or yunsuan"-"or yunsuan"/"or yunsuan"%"
  • 问题2:对在列表中增减元素不熟练
  • 问题2解决方案:原先语句是 b=[float(input())] ,改为 b.append(float(input()))

其他(感悟、思考等)

还不能完全灵活运用知识,目前无法做到使整个程序可以循环运行;
遇到错误就应该调试改进,始终不知道自己错误在哪里的时候可以换个方式表达某语句。

参考资料

附码云链接:https://gitee.com/python_programming/ccxsjyy/blob/master/shiyan2.py

posted @ 2020-04-12 17:15  191108  阅读(287)  评论(0编辑  收藏  举报