def test_add(): """ Every possibility INT between 1 and 200 are tested to filter any minor errors. """ for num_1 in range(1, 201): for num_2 in range(1, 201): for num_3 in range(1, 201): add_value = ( num_1 + num_2 + num_3 ) # addition of every possbility of given intiger range assert add(num_1, num_2, num_3) == add_value
def test_add(self): self.assertEqual(add(1, 2), 3) self.assertEqual(add(2, 2), 4) self.assertEqual(add(-2, 2), 0)
def test_add(): assert add(2, 1) == 3
import function while True: print("") g = input("L)ihat, T)ambah, U)bah, H)apus, K)eluar: ") # Untuk keluar dari program if g.lower() == "k": print("you exit from program") break # untuk melihat list elif g.lower() == "l": function.read() # Untuk menambahkan data elif g.lower() == "t": function.add() # Untuk mengubah data elif g.lower() == "u": function.edit() # Untuk menghapus data elif g.lower() == "h": function.delete() else: print("Pilih Menu Yang Tersedia")
def test_add_4(): assert function.add(10, 20) == 30
b1 = Button(f2, padx=100, pady=15, bd=8, fg="Black", command=viewData, font=("arial", 10), text="Show", bg="indigo") b1.grid(row=0, column=0) b2 = Button(f2, padx=100, pady=15, bd=8, fg="Black", command=lambda: function.add(name.get(), author.get(), book_no.get( ), isbn.get()), font=("arial", 10), text="Add", bg="indigo") b2.grid(row=1, column=0) b3 = Button(f2, padx=100, pady=15, bd=8, fg="Black", command=lambda: function.delete(name.get(), isbn.get()), font=("arial", 10), text="Delete", bg="indigo") b3.grid(row=2, column=0) b4 = Button(
import function value = function.add(5, 3) print(value)
import function work = True while work: znak = input('Введите знак(для остановки введите stop.): ') if znak == 'stop': work = False break a = float(input('Введите число: ')) b = float(input('Введите число: ')) if znak == '+': print(function.add(a, b)) elif znak == '-': print(function.min(a, b)) elif znak == '*': print(function.mul(a, b)) elif znak == '/': print(function.delen(a, b))
import function a = int(input("first num")) b = int(input("second num")) function.add(a, b) function.sub(5, 3)
import function as F print(F.add(3, 9)) '''def add(a, b): c = a + b return c if __name__ == '__main__': #运算不出结果,多半是这里出问题了 只执行下面这个函数 别人调用的不执行 d = add(1, 58) print(d)'''
import function print(function.add(4, 6))
def test_add_2(): assert function.add(2, 4) == 6
def test_add(): assert function.add(1, 2) == 3
def test_add_6(): assert function.add(-2, -2) == -4
def test_add_5(): assert function.add(0, 0) == 0
def test_add(self): self.assertEqual(add(5,6),11)
|--function.py |--mainProcedures.py ---function.py def add(list_temp): return sum(list_temp) def merge(list_temp): return '_'.join([str(x) for x in list_temp]) ---mainProcedures.py import function list_a = [1,3] result1 = function.add(list_a) result2 = function.merge(list_a) print(result1) 返回4 print(result2) 返回1_3
from function import add t = add(8, 9) print(t)
import function print(function.add(10, 20))
raise TypeError except IOError as e: print("wrong error") except TypeError as e: print(e) else: # if there is no error, and try block works print("no error") finally: print("always do this") def add(a, b): return a + b add (3, 6) # prints 9 import function # import external file named function.py function.add(5, 6) # prints 11 from function import greet # imports greet from function.py function.length([1,2,3,4,5]) # length function from function.py takes in a list # prints 5 function.total(1,3,5,7,9,11,13,17,19) # prints 85 function.total(1,3,5,7,9,11,13,15,17,19) # prints 100 # optional arguments def greet(person, excited=False, **kwargs) if excited: return "Hello {}!!".format(person); else: return "Hello {}.".format(person);
# ord() 将字符串(一个字符)转换成对应的编码(整数) # 运算符 ''' 运算符 描述 [] [:]:下标,切片 **:指数 ~ + -:按位取反, 正负号 * / % //:乘,除,模,整除 + -:加,减 >> <<:右移,左移 &:按位与 ^ |:按位异或,按位或 <= < > >=:小于等于,小于,大于,大于等于 == !=:等于,不等于 is is not:身份运算符 in not in:成员运算符 not or and:逻辑运算符 = += -= *= /= %= //= **= &= |= ^= >>= <<= (复合)赋值运算符 ''' from function import add add()
import function x = input("enter the numer") y = input("enter the numer") a = function.add(int(x), int(y)) print(a)
import function a = function.add(2, 3) print a
def test_add_3(): assert function.add(3, 7) == 10