python实验报告二

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


课程:《Python程序设计》
班级: 202222
姓名: 李元浩
学号:20222212
实验教师:王志强
实验日期:202年3月27日
必修/选修: 公选课


## 1.实验内容


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

- 创建工程项目,使用Python语言实现具体的操作运算,并完成程序调试和运行,代码托管到码云。


- 注:在华为ECS服务器(OpenOuler系统)和物理机(Windows/Linux系统)上使用VIM、IDLE、Pycharm等工具编程实现。


## 2. 实验过程及结果

编写代码

 1.编写计算操作函数

```python
import math


def Pysin(a):
    return math.sin(math.radians(a))


def sum(a, b):
    return a + b


def delete(a, b):
    return a - b


def multiply(a, b):
    return a * b


def division(a, b):
    return a / b


def log(a,b):
    return math.log(a,b)

def Pycomplex(a, b):
    comlexoperat = input("input 复数运算操作符")
    if comlexoperat == "+":
        print("a+b=", a + b)
        return a + b
    elif comlexoperat == "-":
        print("a-b=", a - b)
        return a - b
    elif comlexoperat == "*":
        print("a*b=", a * b)
        return a * b
    elif comlexoperat == "/":
        print("a/b=", a / b)
        return a / b
    elif comlexoperat == "sin":
        print("sin(a)", Pysin(a))
        return Pysin(a)

```
2. while实现重复使用

```python
flag = True
while flag == True:
    a = eval(input("请输入第一个数a:"))

    b = eval(input("请输入第二个数b:"))
    operator = input("请输入运算符( + - * / sin com log):")
    if operator == "+":
        print("a+b=", sum(a, b))
    elif operator == "-":
        print("a-b=", delete(a, b))
    elif operator == "*":
        print("a*b=", multiply(a, b))
    elif operator == '/':
        if (b == 0):
                 print("zero division error")
        else:
                  print("a/b=", division(a, b))
    elif operator == "sin":
        print("sin a =", Pysin(a), "sin b =", Pysin(b))
    elif operator == "com":
        Pycomplex(a, b)
    elif operator == "log":
        print("log (a,b) =",log(a,b))
    else:
        print("您输入有误,请重新输入")

    flag = False if input("是否要继续?Y OR N\n") == "N" else True


```
3. 操作判断符

```python
    if operator == "+":
        print("a+b=", sum(a, b))
    elif operator == "-":
        print("a-b=", delete(a, b))
    elif operator == "*":
        print("a*b=", multiply(a, b))
    elif operator == '/':
        if (b == 0):
                 print("zero division error")
        else:
                  print("a/b=", division(a, b))
    elif operator == "sin":
        print("sin a =", Pysin(a), "sin b =", Pysin(b))
    elif operator == "com":
        Pycomplex(a, b)
    elif operator == "log":
        print("log (a,b) =",log(a,b))
    else:
        print("您输入有误,请重新输入")


```
4. 结果

![img](https://img-community.csdnimg.cn/images/48c9bca199ab4cc7be987c6bf5eb5a7a.png "#left")

![img](https://img-community.csdnimg.cn/images/c040b52b3557442aaf8557a1d4cceb3d.png "#left")

![img](https://img-community.csdnimg.cn/images/67f08830c489435a8eba1a766173209d.png "#left")

![img](https://img-community.csdnimg.cn/images/bf72f3fc79ad4d50a0d8b5615632cb53.png "#left")

##  3. 实验过程中遇到的问题和解决过程
1.对python内部语法不够熟练:看了书本内容复习后再进行实验

2.除以0时出现问题:将除法分成两种情况,除以0和除以非0

## 4.其他(感悟、思考等)
在本次实验中发现自己对代码还是不够熟悉,敲代码的速度远远慢于老师同学,在课下还是要勤加联系,多练。

## 参考资料

《零基础学Python》
 

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值