2016-02-29 57 views
0

如何使该程序起作用?数字和用户输入的和产品的总和

问题

我需要设置多少浮数输入用户可以进入。然后将每个输入乘以一个数字并对每个产品进行求和。

代码

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

+0

请不要污蔑你的问题。这里的问题旨在帮助未来的游客*遇到同样的问题,而不仅仅是你。 –

回答

0

你可以这样来做:

userInput = int(input("Enter how many numbers you would like to input? ")) 
multiplicand = int(input("Enter the multiplicand: ")) 
ans = 0 
for x in range(userInput): 
    num = float(input("What is the value of number " + str(x) + " ? ")) 
    ans += num*multiplicand 

print(ans) 
1
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 "+str(x+1)+"?")) 
multiplicand = int(input("Enter the multiplicand: ")) 
l = sum(numList)*multiplicand 
print (l) 
0

这应该解决乌尔概率: `

temp1 = 1 
temp2 = 0 
user_input=[] 
no_of_input=int(input("Enter how many numbers you would like to input? ")) 

for i in range(0,no_of_input) : 
    num=float(input("enter input {0}".format(i+1))) 
    user_input.append(num) 

multiplicand=float(input(("enter the multiplicand"))) 



for j in range(0,no_of_input) : 
    temp1=multiplicand * user_input[j] 
    temp2= temp2 + temp1 



print("total value is {0}".format(temp2)) 

`