110
社区成员
发帖
与我相关
我的任务
分享20222224 2023-2024-2 《Python程序设计》实验二报告
课程:《Python程序设计》
班级: 2222
姓名: 张耀文
学号:20222224
实验教师:王志强
实验日期:2024年3月29日
必修/选修: 公选课
1.实验内容
设计并完成一个完整的应用程序,完成加减乘除模等运算,功能多多益善。
考核基本语法、判定语句、循环语句、逻辑运算等知识点
2. 实验过程及结果
程序代码
import math
def sum(a,b):
print(a+b)
def sub(a,b):
print(a-b)
def mul(a,b):
print(a*b)
def div(a,b):
if(b==0):
print("error")
else:
print(a/b)
def pow(a,b):
print(a**b)
def factorial(a):
rec=1
for n in range(1,a+1):
rec=rec*n
print(rec)
def log(a,b):
print(math.log(b,a))
while 1:
a=int(input("a="))
b=int(input("b="))
operation=input("请输入您需要的操作:+-*/**!log")
if(operation=='+'):
sum(a,b)
if(operation=='-'):
sub(a,b)
if(operation=='*'):
mul(a,b)
if(operation=='/'):
div(a,b)
if(operation=="**"):
pow(a,b)
if(operation=='!'):
factorial(a)
factorial(b)
if(operation=="log"):
log(a,b)
flag=int(input("是否继续?是输入1,否输入0.\n"))
if(flag==0):
break
实验结果

将代码托管到gitee

3. 实验过程中遇到的问题和解决过程
其他(感悟、思考等)
学会了在python里面使用函数的方法。
参考资料
- [《Java程序设计与数据结构教程(第二版)》](https://book.douban.com/subject/26851579/)
- [《Java程序设计与数据结构教程(第二版)》学习指导](http://www.cnblogs.com/rocedu/p/5182332.html)