I am brand new to Python, and I'm currently taking a free online course. Show I'm stuck trying to figure out how to code this simple optional problem found in my course: [ ] using range(x) multiply the numbers 1 through 71x2x3x4x5x6x7 = 5040I have made a variable for the range, 7, and a variable for the product used in the loop:
This is where I'm stuck. I try things in the loop like: product = item * item which doesn't even make any sense. I'm having a total mental block right now. I realize this should be an easy thing to do, but can't for whatever reason. I've tried making other variables like "number" and "previous_number" to make things easier for me, but I just get confused. I need to use a for loop in this solution. I'm just not understanding the logic right now. A solution and explanation would be great! Please help! asked Jul 12, 2017 at 20:43
1 Check this out:
answered Jul 12, 2017 at 20:51
inspectorG4dgetinspectorG4dget 106k25 gold badges137 silver badges234 bronze badges 1 You need to initialise
which is short hand for:
In python there is also a
answered Jul 12, 2017 at 21:02
AChampionAChampion 28.7k3 gold badges54 silver badges70 bronze badges Try something like this:
Note that product starts at one and the range function starts at one as well. Otherwise item will continue to be multiplied by zero. answered Jul 12, 2017 at 20:50
answered May 19, 2018 at 10:12
1
Tomerikoo 16.6k15 gold badges37 silver badges54 bronze badges answered Jan 25, 2020 at 22:49
greybeard 2,1087 gold badges25 silver badges59 bronze badges answered Dec 27, 2020 at 4:10
1 Try this:
answered Mar 20 at 17:10
How do you multiply a range?1. Select a blank cell, says Cell E1, and type the formula =A1*$D$1 (A1 is the first cell of the range you will multiply with the same number, D1 is the cell with the specified number you will multiply with) into it, and press the Enter key.
How do you multiply a whole list in Python?Use the syntax [element * number for element in list] to multiply each element in list by number .. a_list = [1, 2, 3]. multiplied_list = [element * 2 for element in a_list]. print(multiplied_list). How do you multiply multiple inputs in Python?how to multiply inputs in python. x = input("give me the number you want to multiply"). y = input("give me the second number you want to multiply"). y = int(y). x = int(x). print (y * x). How do you multiply an array in Python?multiply() in Python. numpy. multiply() function is used when we want to compute the multiplication of two array. It returns the product of arr1 and arr2, element-wise.
|