我决定制造一个计算器,所以我需要在其他数字上加上数字,因此数字必须是一个变量,如何将所有整数和浮点数字存储到一个变量中。
答案 0 :(得分:0)
您需要使用一个列表。这是一个例子。
number_list = [1, 2, 3, 4, 5]
def addition(number_list):
result = 0
for number in number_list: # the for loop will iterate every number of your list one by one
result += number # Which does the same as result = result + number
return result
# if you want to see the result in the terminal, you can print the result with:
print(addition(number_list)