[Python] 功課好難做 求救

71 回覆
2 Like 21 Dislike
2020-11-18 03:01:21
咪害人啦仆街
2020-11-18 03:12:34
而家sen尾都唔識Python基礎嘢
樓主讀緊咩U同hea咗幾耐
2020-11-18 03:19:02
BTW,功課應該會寫唔俾用乜乜library,唔俾人走捷徑
2020-11-18 04:33:49
樓主你不如上google/ stackoverflow搵下先。
你咁樣下下唔識都依到問,一嚟好少會有人幫你做功課,二嚟依家咁簡單嘅題目google下都唔肯,少少problem solving skill都冇,咁你之後讀嗰啲仲加唔會明。
2020-11-18 05:30:05
你唔講卡係邊個位 你想人點幫你

定係打算叫人幫你做就算
2020-11-18 09:48:09
freerider
2020-11-18 09:57:00
根據傳統你提問個時可以列出問題, 你想要既結果, 同埋你現時既代碼
2020-11-18 10:04:50
睇曬大家意見今日繼續嘗試做埋佢
2020-11-18 10:06:09
嗱巴打,你簡化個問題,諗吓點計一個數嘅factorial先,留意range(a,b)係唔包b,之後你要做嘅野就係由1 loop到 n,逐個搵factorial,心水清的話就係nested for loop
2020-11-18 10:47:34

其實factorial我係識點寫,只係唔識圖括住嗰啲野。唔明點樣可以loop曬由1-8嘅factorial出黎
2020-11-18 10:50:01
其實我琴晚都Google咗好耐,無耐嘅係唔知要查啲咩關鍵字先搵到點做
2020-11-18 11:04:16
咪係囉, functional program 都唔洗
鳩乘就得都唔識真係弱智
2020-11-18 11:25:54
我識點樣做factorial
2020-11-18 11:30:35
factorial 點解?

識Python 唔識英文
2020-11-18 11:50:19
def getFacNumList(n: int):
    result = list()
    for i in range(1, n + 1):
        x = 1
        for y in [z for z in range(1, i + 1)]:
            x *= y
        result.append(x)
    return result

def dispFacNumList(flist: list):
    msg = 'Factorial numbers are:'
    for x in range(len(flist)):
        msg += f'\nn={x + 1}\t: n!={flist[x]}'
    print(msg)

dispFacNumList(getFacNumList(4))
2020-11-18 12:10:35
sor鳩囉 打錯字
2020-11-18 12:11:28
你唔講我都唔知你串錯
我本身真係唔識 factorial 呢個字
都係GOOGLE下咁LO
2020-11-18 14:52:50
2020-11-18 15:56:58
2020-11-18 19:19:37
睇咗好耐都係唔明點樣用result.append(x)
2020-11-18 20:04:37
咁樣會唔會明D


def getFacNumList(n: int):
    result = list()
    for i in range(1, n + 1):
        x = 1
        for y in [z for z in range(1, i + 1)]:
            x *= y
        result = result + [x]
    return result
2020-11-18 20:08:40
okok明白唔該ching,不過都想問下點解要寫 for y in [z for z in range(1, i + 1)]:,有冇其他方法可以取代。特別唔明點解要
2020-11-18 20:14:46
3個 for loop

[z for z in range(1, i + 1)]

呢個用黎for 由, 1 數到 i + 1 的每一個數
i = 7
>> [1, 2, 3, 4, 5 ,6, 7]


for y in [z for z in range(1, i + 1)]:

呢個用黎將 1 到 i + 1 的每一個相乘, 計個 FacNum 出黎
>> 1 x 2 x 3 x 4 x 5 x 6 x 7


for i in range(1, n + 1):

呢個用黎for 你 input 既每一個數計一個 FacNum 出黎


唔咁寫得唔得
得, 將以上既code寫埋做一行都得
但你番學咁寫差不多啦
吹水台自選台熱 門最 新手機台時事台政事台World體育台娛樂台動漫台Apps台遊戲台影視台講故台健康台感情台家庭台潮流台美容台上班台財經台房屋台飲食台旅遊台學術台校園台汽車台音樂台創意台硬件台電器台攝影台玩具台寵物台軟件台活動台電訊台直播台站務台黑 洞