2016-02-29 53 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)) 

`