20232308 2023-2024-2 《Python程序设计》实验二报告

20232308胡正源 2024-03-27 23:15:39

课程:《Python程序设计》
班级: 2323
姓名: 胡正源
学号:20232308
实验教师:王志强
实验日期:2024年3月27日
必修/选修: 公选课
1.实验内容
设计并完成一个完整的应用程序,完成加减乘除模等运算,功能多多益善。
2. 实验过程及结果
程序如下

import math

def sum(a,b):
    return (a+b)
def sub(a,b):
    return (a-b)
def mul(a,b):
    return (a*b)
def div(a,b):
    if b==0:
        print("输入错误")
        return b
    else: return (a/b)
def pylog(a,b):
    return math.log(b,a)
def pysin(a):
    return math.sin(math.radians(a))
def pycos(a):
    return math.cos(math.radians(a))
print("======欢迎使用BESTI计算器======")
print("      作者 20232308hzy")
print("============================")
print("      开发时间2024.03.27")
print("  Copyright(c) 2024 by BESTI")
print("============================")

flag = True
while flag:
    a = int(input("请输入a: "))
    b = eval(input("请输入b: "))
    operator = input("请输入运算符 ")
    if operator == "+":
        print("a+b = ",sum(a,b))

    if operator == "-":
        print("a-b = ",sub(a,b))

    if operator == "*":
        print("a*b = ",mul(a,b))

    if operator == "/":
        print("a/b = ",div(a,b))

    if operator == "sin":
        print("sin(a) = ",pysin(a))
        print("sin(b) = ",pysin(b))

    if operator == "cos":
        print("cos(a) = ",pycos(a))
        print("cos(b) = ",pycos(b))

    if operator == "com":
        print("com = ",pycomplex(a,b))

    if operator == "log":
        print("log(a) b = ",pylog(a,b))

    choice = str (input("是否要继续?Y/N "))
    if choice.lower() == "n":
        flag = False


img

3. 实验过程中遇到的问题和解决过程
问题1:无法实现重复
问题1解决方案:设置一个flag,通过其ture or false。
感悟
在完成这段代码的过程中,充分体会到了python的简便性,更人性化,更有助于提高能力与思维能力。

...全文
55 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110

社区成员

发帖
与我相关
我的任务
社区描述
人生苦短,我用Python!
python3.11 高校
社区管理员
  • blackwall0321
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧