创建自定义模块MyMath,实现两个数的加减乘除运算(各运算用函数实现),并在本模块中实现数据测试,在另一个模块中用两种方式导入MyMath模块,并调用各函数实现相应功能。
时间: 2024-02-27 07:56:46 浏览: 69
后的姓名:");
String stuName = scanner.nextLine();
System.out.println("请输入修改后的性别:");
String stuGender = scanner.nextLine();
System.out.println("请输入修改后的专业:");
String stuMajor = scanner.nextLine();
好的,这是一个关于Python编程的问题。以下是实现的代码示例:
1. 创建MyMath模 String updateSql = "UPDATE student_info SET stu_name = '" + stuName + "', stu_gender = '" + stuGender
+块,实现加减乘除四个函数。
```python
# MyMath.py
def add(x, y):
return x "', stu_major = '" + stuMajor + "' WHERE stu_no = '" + stuNo + "'";
stmt.executeUpdate(updateSql);
System + y
def sub(x, y):
return x - y
def mul(x, y):
return x * y
def div.out.println("学生信息修改成功!");
} else {
System.out.println("未找到该学生信息!");
}
(x, y):
if y == 0:
return "Error: division by zero"
return x / y
```
2 } catch (SQLException e) {
e.printStackTrace();
}
}
// 删除学生信息
private static void delete. 在MyMath模块中实现数据测试。
```python
# MyMath.py
def test():
assert add(2,StudentInfo() {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要删除的学生学号:");
3) == 5
assert sub(5, 3) == 2
assert mul(2, 3) String stuNo = scanner.nextLine();
try {
stmt = conn.createStatement();
String sql = "SELECT * FROM student_info WHERE == 6
assert div(6, 3) == 2
assert div(6, 0) == "Error stu_no = '" + stuNo + "'";
rs = stmt.executeQuery(sql);
if (rs.next()) {
String deleteSql =: division by zero"
print("All tests passed!")
```
3. 在另一个模块中用import语句导入My "DELETE FROM student_info WHERE stu_no = '" + stuNo + "'";
stmt.executeUpdate(deleteSql);
System.out.println("学生Math模块,并调用各函数实现相应功能。
方式一:
```python
# main1.py
import MyMath
信息删除成功!");
} else {
System.out.println("未找到该学生信息!");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
// 身份证号校验
private static boolean isIdcardValid(StringMyMath.test()
print(MyMath.add(2, 3))
print(MyMath.sub(5, 3))
print(MyMath.mul(2, 3))
print(MyMath.div(6, 3))
```
方式二:
```python
# main2.py
from idcard) {
// 省略身份证号校验逻辑
return true;
}
}
```
阅读全文