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')

分福茶釜

這個扭蛋是關於一則日本民間故事~分福茶釜。日本群馬縣茂林寺有保存一個茶釜,據說這個茶釜是由一隻狸貓變身成的。 傳說很久以前有一位生活貧困的老先生,他在野外發現一隻狸貓被陷阱所困,然後這位老先生立即救了這支狸貓。為了感謝老先生的恩德,狸貓變身成茶釜並建議老先生賣掉茶釜換成錢來改善生...