Python 数字与用户输入的乘积之和
我如何使这个程序工作 问题 我需要设置用户可以输入多少个浮点输入。然后将每个输入乘以一个数字,然后对每个乘积求和 代码Python 数字与用户输入的乘积之和,python,python-3.x,Python,Python 3.x,我如何使这个程序工作 问题 我需要设置用户可以输入多少个浮点输入。然后将每个输入乘以一个数字,然后对每个乘积求和 代码 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
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)
输出应如下所示:
输入要输入的数字数?三,
数字1的值是多少?二,
数字2的值是多少?三,
数字3的值是多少?一,
输入被乘数:5
总值为:30您可以这样做:
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)
这将解决您的问题: `
`请不要诋毁你的问题。这里的问题旨在帮助未来的访问者解决同样的问题,而不仅仅是你。
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)
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))