Пример #1
0
def test_sub_2_with_1_expect_1():
    assert add.sub(2, 1) == 1
Пример #2
0
# Eg : Car --> Accelerator, Gear, Clutch, Brake
# Showing only the fuctionality not the code

# If we want to use modules we have to use import
'''
import math
print(math.factorial(5))
print(math.floor(5.2))
print(math.ceil(5.2))
print(int(math.pow(5, 3)))'''

# Group of functions, variables and classes
import add
#print(add.num)
print(add.add())
print(add.sub())
print(add.add() * add.sub())

# Module Aliasing

import add as a
print(a.add())

print()
# only specific function from the modules
from add import sub
print(sub())

from add import add
print(add())
Пример #3
0
 def test_sub(self):
     result = add.sub(10, 5)
     self.assertEqual(result, 5)
Пример #4
0
'''
__name__属性:不运行模块的代码,只是运行自己的代码
格式:
if __name__ == "__main__"
    pass
'''
import add

if __name__ == "__main__":
    print(add.add(100,200))
    print(add.sub(100,200))

Пример #5
0
import add as a

x=int(input("Enter a Number"))
y=int((input("Enter a Number")))
z=a.add(x,y)
y=a.sub(x,y)
print(z)
print(y)
Пример #6
0
#from……import语句
#作用:从模块中导入一个指定的部分到当前命名空间
#格式:from module import name1[, name2[, ……namen]]

from add import add, sub
#from add import * #不建议这么用
'''
程序内容的函数可以将模块中的同名函数覆盖
def add(num1, num2):
    print("*********")
    return
'''
print(add(100, 200))
print(sub(100, 200))