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

20222224 2024-03-29 18:42:24

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

课程:《Python程序设计》
班级: 2222
姓名: 张耀文
学号:20222224
实验教师:王志强
实验日期:2024年3月29日
必修/选修: 公选课

1.实验内容

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

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

2. 实验过程及结果

  • 程序代码

    
     
    1. import math

    2. def sum(a,b):

    3. print(a+b)

    4. def sub(a,b):

    5. print(a-b)

    6. def mul(a,b):

    7. print(a*b)

    8. def div(a,b):

    9. if(b==0):

    10. print("error")

    11. else:

    12. print(a/b)

    13. def pow(a,b):

    14. print(a**b)

    15. def factorial(a):

    16. rec=1

    17. for n in range(1,a+1):

    18. rec=rec*n

    19. print(rec)

    20. def log(a,b):

    21. print(math.log(b,a))

    22. while 1:

    23. a=int(input("a="))

    24. b=int(input("b="))

    25. operation=input("请输入您需要的操作:+-*/**!log")

    26. if(operation=='+'):

    27. sum(a,b)

    28. if(operation=='-'):

    29. sub(a,b)

    30. if(operation=='*'):

    31. mul(a,b)

    32. if(operation=='/'):

    33. div(a,b)

    34. if(operation=="**"):

    35. pow(a,b)

    36. if(operation=='!'):

    37. factorial(a)

    38. factorial(b)

    39. if(operation=="log"):

    40. log(a,b)

    41. flag=int(input("是否继续?是输入1,否输入0.\n"))

    42. if(flag==0):

    43. break

  • 实验结果

     

  • 输入操作数以及操作符,执行相应的操作。每次操作完成后,输入1则继续进行计算,输入0则结束程序

     

  • 将代码托管到gitee

  •  

     

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

  • 问题1:归零的循环总是不对
  • 问题1解决方案:理清思路,不总想着用简单的代码实现,按部就班地写。

其他(感悟、思考等)

学会了在python里面使用函数的方法。

    参考资料

    -  [《Java程序设计与数据结构教程(第二版)》](https://book.douban.com/subject/26851579/)

    -  [《Java程序设计与数据结构教程(第二版)》学习指导](http://www.cnblogs.com/rocedu/p/5182332.html)

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

    110

    社区成员

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

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