20232416 2023-2024-2 《python程序设计》实验二报告

该实验报告详细描述了一个Python程序,包含了基本运算、三角函数、复数运算以及对用户输入的逻辑判断。程序实现了加减乘除、三角函数计算、复数运算和对用户输入的正确性检查,展示了学生在实践中对Python语法和控制结构的理解。
摘要由CSDN通过智能技术生成

20232416 2023-2024-2 《python程序设计》实验二报告

课程:《Python程序设计》
班级: 2324
姓名: 石泽伟
学号:20232416
实验教师:王志强
实验日期:2024年3月27日
必修/选修: 公选课

1.实验内容

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

2. 实验过程及结果

import math
def ldtriangle(a,b):
    triangleop = input("请输入操作: ")
    if triangleop == "sin":
        print("sin(a) = ",math.sin(math.radians(a)),"sin(b) = ",math.sin(math.radians(b)))
    elif triangleop == "cos":
        print("cos(a) = ",math.cos(math.radians(a)),"cos(b) = ",math.cos(math.radians(b)))
    elif triangleop == "tan":
        print("tan(a) = ",math.tan(math.radians(a)),"tan(b) = ",math.tan(math.radians(b)))
    elif triangleop == "sec":
        print("sec(a) = ",1.0/math.sin(math.radians(a)),"sec(b) = ",1.0/math.cos(math.radians(b)))
    elif triangleop == "csc":
        print("csc(a) = ",1.0/math.cos(math.radians(a)),"cos(b) = ",1.0/math.cos(math.radians(b)))

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("ZerodivisionError")
        return None
    return (a/b)

def ldcomplex(a,b):
    complexoper = input("请输入复数运算符(+-*/):")

    if complexoper == "+":
        print("a+b=",a+b)
    elif complexoper == "-":
        print("a-b=", a - b)
    elif complexoper == "*":
        print("a*b=", a * b)
    elif complexoper == "/":
        print("a/b=", a / b)

def ldlog(a,b):
    if a <= 0 or b <= 0:
        print("a b 需大于0")
        return

    result = math.log(b) / math.log(a)
    print("logaB = ",result)

print("**=========欢迎使用积极计算器=========**")
print("||           作者:          ||")
print("||   开发时间:2024.3.27            ||")
print("||   联系方式:laoda@los angles.com ||")
print("**================================**")
flag = True
while flag:
    a = eval(input("请输入a: "))
    b = eval(input("请输入b: "))
    operate = input("请输入运算符(+-*/ tri com lg): \n")
    if operate == "+":
        print("a+b=",sum(a,b))
    elif operate == "-":
        print("a-b=",sub(a,b))
    elif operate == "*":
        print("a*b=",mul(a,b))
    elif operate == "/":
        print("a/b=",div(a,b))
    elif operate == "tri":
        ldtriangle(a,b)
    elif operate == "com":
        ldcomplex(a,b)
    elif operate == "lg":
        ldlog(a,b)
    else:
    print("您输入有误,请重新输入: ")
    flag = False if input("是否继续?y or n\n") == "n" else True
 

在这里插入图片描述这里展示一部分的功能,所有功能均可正常运行。

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

  • 1.问题:一开始的程序中判断是否会继续输入,
  • 解决方案:使用一个简化式,就像C语言中的这个程序一样。
max = a > b ? a:b;
  • 9
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值