【发布时间】:2016-02-29 05:28:32
【问题描述】:
如何让这个程序发挥作用?
问题
我需要设置用户可以输入多少个浮点输入。然后将每个输入乘以一个数字并对每个乘积求和。
代码
userInput = int(input("Enter how many numbers you would like to input? "))
numList = [None] * userInput
for x in range(userInput):
numList[x] = float(input("What is the value of number 1? "))
multiplicand = int(input("Enter the multiplicand: "))
for y in numList:
product = multiplicand * y
sumOfproduct = sum(product)
print(sumOfproduct)
输出应如下所示:
输入您想输入多少个数字? 3
数字 1 的值是多少? 2
数字 2 的值是多少? 3
数字 3 的值是多少? 1
输入被乘数:5
总价值为:30
【问题讨论】:
-
请不要破坏您的问题。这里的问题旨在帮助未来的访客遇到同样的问题,而不仅仅是您。
标签: python python-3.x