如何制作一个包含7个(或任意数量)空元素的python列表?
我正在尝试创建一个具有一定数量的元素的空列表。
我知道怎么列一张空单子。
选择 | 换行 | 行号
- x = []
我也知道如何列出一份正常的清单。
选择 | 换行 | 行号
- x = ["d","x","f"]
我正在努力做到以下几点。
选择 | 换行 | 行号
- #set amount of elements
- SIZE = 7
- array = [SIZE]
我想让数组变量包含7个空元素,而不是值7。有人能帮忙吗?
更新*
我想通了。
我想要编写一个程序,让用户输入当天的总销售额,然后我的程序将输出一周的总销售额。
以下是我的代码:
选择 | 换行 | 行号
- def main():
- total = 0.0
- SIZE = 7
- sales = [0] * SIZE
- index = 0
- day = ["Monday","Tuesday","Wednsday","Thursday","Friday","Saturday","Sunday"]
- for index in range(SIZE):
- print "Enter the amount of sales for", day[index]
- sales[index] = float(raw_input("Enter the sales here: "))
- total = total + sales[index]
- print "The total sales for the week is $",total
- main()