国标要求:
测试流程示例:
变量的设置:
原生代码:
# coding: utf-8
import sys
import traceback
from ioHelper import *
def Process(data) -> int:
"""Write custom logic code inside the Process method. Return 0 for success or any other value for failure."""
"""在Process方法内编写自定义逻辑代码, 成功返回0, 返回其他值表示失败"""
"""Do not delete this code block."""
"""请勿删除此处代码"""
moduleVar = IoHelper(data, INIT_MODULE_VAR)
globalVar = IoHelper(data, INIT_GLOBAL_VAR)
"""Variable initialization, to access input and output variables within the Process method."""
"""变量初始化, 进入Process方法后首先调用, 否则无法访问输入、输出变量"""
"""
* Input and output variables:
* 输入、输出变量
Input variables are read-only and cannot be modified; output variables are write-only and cannot be read.
输入变量为只读, 不可以修改; 输出变量为只写, 不可以读取;
Assume: the name of the input variable is 'in0', of type int. Its value can be obtained using tmp = moduleVar.in0
假设: 输入变量名为in0, 类型为int, 可通过tmp = moduleVar.in0 读取该变量的值
Assume: the name of the output variable is 'out0', of type int. Its value can be set using moduleVar.out = 9
假设: 输出变量名为out0, 类型为int, moduleVar.out = 9 设置该变量的值
Global variables:
* 全局变量
Assume: the name of the global variable is 'var0', of type int. Its value can be obtained using tmp = globalVar.var0
假设: 输入变量名为var0, 类型为int, 可通过tmp = globalVar.var0 读取该变量的值
Local variables:
** All variables should be used strictly based on their types. If there is a need for type conversion, explicit conversion should be performed in the user code.
** 所有变量都需要严格根据变量类型使用, 若有类型转换的需求, 应在用户代码内通过显示转换代码进行类型转换。
Example code:
示例代码如下:
width = moduleVar.width + 100
moduleVar.out0 = width / 2 + 20
if moduleVar.in1 == 'OK':
moduleVar.out1 = "OK"
moduleVar.out0 = globalVar.var0
moduleVar.out1 = globalVar.var0
globalVar.var1 = globalVar.var0
globalVar.var1 = moduleVar.out2
Note: Python indentation must be 4 spaces
注意: Python的缩进必须为4个空格。
"""
len_result = len(moduleVar.in0)
moduleVar.out0 = 0
try:
PrintMsg(moduleVar.in0)
pass
#PrintMsg("User code end")
sResult = moduleVar.in0 # 假设输入数据通过moduleVar.in0获取
#PrintMsg(sResult)
if len_result == 17:
bError = 0
total = 0
for i in range(1, 18):
temp = ord(sResult[i-1]) - 48
#PrintMsg(sResult[i-1])
#PrintMsg(temp)
if temp == 15:
bError = 1
if temp>9:
temp=temp-16
if temp>9:
temp=temp-9
if temp>9:
temp=temp-8
if i == 9:
temp = 0
#PrintMsg(temp)
site = 9 - (i % 10)
if site == 1:
site = 10
total = total + site * temp
#PrintMsg(site)
#PrintMsg(temp)
#PrintMsg(total)
totalx = total % 11
totals = ord(sResult[8]) - 48
if totals > 9:
totals = 10
if totalx == totals:
moduleVar.out0 = 1
if bError == 1:
moduleVar.out0 = 0# 假设输出结果通过moduleVar.out0设置
else:
moduleVar.out0 = -1# 如果数据长度不正确,设置输出结果为-1
PrintMsg(moduleVar.out0)
#PrintMsg(totalx)
#PrintMsg(totals)
except BaseException as e:
err_stack = traceback.format_exc()
PrintMsg('\n-----------\n' + err_stack)
return 0