在信用卡背面,
從左到右,最左邊單獨一個的數字不用看,
接下來前3個數字不用看,
會員卡號從第4個數字開始看,到倒數第2個數字。
一共8碼,也就是最後一個,最右邊的數字不用看。
class Solution: def byValue(self, t, m = [0]): print('m=', m) for i in t: m = [i] return m def byRef(self, t, m = [0]): print('m=', m) for i in t: m[0] = i return m def byValue1(self, t, m = 0): print('m=', m) for i in t: m = 1 return m def byValue2(self, t, m = 0): print('m=', m) for i in t: m = 2 return m def main(): a = Solution() print('byRef') print(a.byRef(['good'])) print(a.byRef(['afternoon'])) print('byValue') print(a.byValue(['fine.'])) print(a.byValue(['thanks'])) print('byValue1') print(a.byValue1(['good'])) print(a.byValue1(['afternoon'])) print('byValue2') print(a.byValue2(['fine.'])) print(a.byValue2(['thanks'])) if __name__ == "__main__": main()
For python 3:
/* File : example.c */
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
Interface file
/* example.i */ %module example %{ /* Put header files here or function declarations like below */ extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time(); %} extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time();Building a Python module
D:\temp\Documents\Python_call_C\example>swig -python -py3 example.i D:\temp\Documents\Python_call_C\example>gcc -c example.c example_wrap.c -I"D:\Program Files (x86)\Python36-32\include" D:\temp\Documents\Python_call_C\example>gcc -shared example.o example_wrap.o "D:\Program Files (x86)\Python36-32\python36.dll" "C:\Windows\System32\msvcr120.dll" -o _example.pydWe can now use the Python module:import exampleprint(example.fact(5))print(example.my_mod(7,3))print(example.get_time())>>>>>>>>>>>>>>>>>>>>>>Example Result:120 1 Sun Aug 26 21:26:01 2018
1. Install Lean Environment: https://lean-lang.org/install/ 試著完Step one, two, three 2. 在VS code下,建一新的project: 取名Hello_World 3. 嘗試執行Main.lea...