Python - combination


def combination(m,n):
    if n==0 or m==n:
        return 1
    else:
        return combination(m-1,n)+combination(m-1,n-1)
    
    
m = int(input('please fill m value :'))
n = int(input('please fill n value :'))
ans = combination(m,n)
print(ans)

Python - summation


def summation(num):
    if num == 1:
        return 1
    else:
        return num + summation(num-1)

n = int(input('please fill in an integer number :'))
ans = summation(n)
print('the result is :', ans)

Python - adding label


def label(sentence):
    y = str('

') + sentence + str('

') print(y) s = str(input('please paste code :')) ans = label(s)

Python - 查日期


from datetime import datetime
#import datetime
def ymd():
    now = datetime.now()
    return (now.year, now.month, now.day)
y, m, d = ymd()
print(y,m,d)

Python - 質數檢查


import math
def prime(num):
    j = 2
    while j<=math.sqrt(num):
        if(num % j == 0):
            return False
        j += 1
    return True
for i in range(2,101):
    if prime(i):
        print(i,'is prime number')

類神經學習筆記(一)

 def km_to_mile(km):     return km / 1.609  # 真實轉換值 # 初始設定 km = float(input("請輸入公里數:")) true_mile = km_to_mile(km) factor = 0.5  #...