def phc(f, i, c): F = f * c I = i * c globa = factorial(F, F - I) / F**I parti = (factorial(f, f - i) / f**i)**c return { 'global': globa, 'partition': parti, 'performance': format(parti / globa, '.2f'), }
import mymath as m a, b = 26, 16 if __name__ == '__main__': print(__name__) print(m.__name__) print(m.pi) print(m.gcd(a, b)) print(m.factorial(6))
def main(): print('Hello Pythin') print('pi is ' + str(mymath.pi)) print('gcd(%d, %d) is %d' % (a, b, mymath.gcd(a, b))) print('factorial(%d) is %d' % (6, mymath.factorial(6))) print('Bye Python')
import mymath print('---Hello Python 3.5.2---') print('pi is ' + str(mymath.pi)) print('gcd of 24 and 16 is ' + str(mymath.gcd(24, 16))) print('factoirial of 6 is ' + str(mymath.factorial(6))) print('---Bye Python 3.5.2---') if __name__ == '__main__': print("as main program") else: print("as module")
def main(): print('Hello Python') print('pi is ' + str(mymath.pi)) print('gcd(%d, %d) is %d' % (a, b, mymath.gcd(a, b))) print('factorial(%d) is %d' % (6, mymath.factorial(6))) print('Bye Python')
def test_wz(): assert factorial(5) == 5 * 4 * 3 * 2
#import mymath #from mymath import pi, gcd, factorial import mymath as m print('Hello Python') print('pi is ' + str(m.pi)) print('gcd of 24 and 16 is ' + str(m.gcd(24, 16))) print('factorial of 6 is ' + str(m.factorial(6))) print('Bye Python') if __name__ == '__main__': print('myhello as main program') else: print('myhello as module')
x = int(input("Enter 1st number: ")) y = int(input("Enter 2nd number: ")) print() # Call the add function resAdd = mymath.add(x, y) print("Sum =", resAdd) #Call the subtract function resSub = mymath.subtract(x, y) print("Difference =", resSub) #Call the multiply function resMul = mymath.multiply(x, y) print("Product =", resMul) #Call the divide function resDiv = mymath.divide(x, y) print("Division =", resDiv) print() #Call the isPrime function resPri = mymath.isPrime(x) if resPri == True: print(x, "is Prime") else: print(x, "is not Prime") #Call the factorial function resFac = mymath.factorial(y) print(y, "Factorial =", resFac)
import mymath print('pi is ' + str(mymath.pi)) print('gcd of 24 and 16 is ' + str(mymath.gcd(24, 16))) print('factorial of 6 is ' + str(mymath.factorial(6))) if __name__ == '__main__': print('myhello as main program') else: print('myhello as module')
Created on Thu Apr 8 17:31:19 2021 @author: Ivan 內容來自:行銷搬進大程式 https://marketingliveincode.com/ 版權屬於「行銷搬進大程式」所有,若有疑問,可聯絡[email protected] Python免費基礎教學課程 第四章Python模組與套件概念 匯入import """ # 匯入套件,也就是整個檔案程式碼 import mymath x = 10 y = 2 c = mymath.factorial(x) / (mymath.factorial(x - y) * mymath.factorial(y)) # as:取小名,不想打太長的套件名稱所使用 import mymath as mm x = 10 y = 2 c = mm.factorial(x) / (mm.factorial(x - y) * mm.factorial(y)) # 從套件中獲取「特定」方法 from mymath import factorial x = 10 y = 2 c = factorial(x) / (factorial(x - y) * factorial(y)) # 從套件中獲取「多個」方法 from mymath import factorial, accumulate
import mymath as m a, b = 26, 16 if __name__ == "__main__": print(__name__) print(m.__name__) print(m.pi) print(m.gcd(a, b)) print(m.factorial(6))