I am currently trying to do an assignment for my programming class and the assignment requires I create a range between 1-10 and input a number in that range. After the input is given the number will be multiplied by the first number in an array of 3 numbers (19, 85, 2). so say I put in the number 2. It would than be multiplied by 19. After the first calculation it will subtract the second element in the array from the total of the first calculation, and after that it will divide the second calculation by the third element in the array. I do not know how to have a number go through separate elements of the same array. Right now I can get the number I input to multiply but it multiplies with all 3 numbers in the array instead of the first.
def multiply( array , n ):
unumb = 0
while 1 > unumb or 10 < unumb:
try:
unumb = int(input("Please enter a number (1 - 10) : "))
except ValueError:
print ("That wasn't an integer in range")
for i in range(n):
unumb = unumb * array[i]
return unumb
array = [19, 85, 2]
n = len(array)
print(multiply(array, n))
Output:
Please enter a number (1 - 10) : 2
6460