日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Python程序:列表乘法

創(chuàng)新互聯(lián)Python教程:

編寫一個(gè) Python 程序,使用 for 循環(huán)范圍執(zhí)行列表乘法。在這個(gè) Python 示例中,我們?cè)试S用戶輸入列表項(xiàng)。接下來,我們使用 for 循環(huán)范圍(for i in range(listNumber))來迭代 multiList 列表項(xiàng)。在循環(huán)中,我們將每個(gè)列表項(xiàng)相乘并打印結(jié)果。

# List Multiplication

multiList = []

listNumber = int(input("Enter the Total List Items = "))
for i in range(1, listNumber + 1):
    listValue = int(input("Enter the %d list Item = " %i))
    multiList.append(listValue)

print("List Items = ", multiList)

listMultiplication = 1

for i in range(listNumber):
    listMultiplication = listMultiplication * multiList[i]

print("The Muliplication of all teh List Items = ", listMultiplication)

使用 For 循環(huán)的 Python 列表乘法程序

# List Multiplication

multiList = []

listNumber = int(input("Enter the Total List Items = "))
for i in range(1, listNumber + 1):
    listValue = int(input("Enter the %d List Item = " %i))
    multiList.append(listValue)

print("List Items = ", multiList)

listMulti = 1

for num in multiList:
    listMulti = listMulti * num

print("The Muliplication of all teh List Items = ", listMulti)
Enter the Total List Items = 5
Enter the 1 List Item = 10
Enter the 2 List Item = 4
Enter the 3 List Item = 9
Enter the 4 List Item = 11
Enter the 5 List Item = 7
List Items =  [10, 4, 9, 11, 7]
The Muliplication of all teh List Items =  27720

這個(gè) Python 程序使用 While 循環(huán)執(zhí)行列表乘法。

# List Multiplication

multiList = []

listNumber = int(input("Enter the Total List Items = "))
for i in range(1, listNumber + 1):
    listValue = int(input("Enter the %d List Item = " %i))
    multiList.append(listValue)

print("List Items = ", multiList)

listMultiplication = 1
i = 0

while (i < listNumber):
    listMultiplication = listMultiplication * multiList[i]
    i = i + 1

print("The Multiplication of all the List Items = ", listMultiplication)
Enter the Total List Items = 4
Enter the 1 List Item = 9
Enter the 2 List Item = 10
Enter the 3 List Item = 2
Enter the 4 List Item = 4
List Items =  [9, 10, 2, 4]
The Multiplication of all the List Items =  720

在這個(gè) Python 列表的例子中,我們創(chuàng)建了一個(gè) list 乘法(multiList)函數(shù),返回結(jié)果 go 列表乘法。

# List Multiplication

def listMultiplication(multiList):
    listMulti = 1

    for num in multiList:
        listMulti = listMulti * num
    return listMulti

multiList = []

listNumber = int(input("Enter the Total List Items = "))
for i in range(1, listNumber + 1):
    listValue = int(input("Enter the %d List Item = " %i))
    multiList.append(listValue)

print("List Items = ", multiList)

listMultip = listMultiplication(multiList)

print("The Multiplication of all the List Items = ", listMultip)
Enter the Total List Items = 3
Enter the 1 List Item = 10
Enter the 2 List Item = 20
Enter the 3 List Item = 8
List Items =  [10, 20, 8]
The Multiplication of all the List Items =  1600

網(wǎng)頁名稱:Python程序:列表乘法
標(biāo)題鏈接:http://www.dlmjj.cn/article/dpggoso.html