Skip to content
Advertisement

How do I make a list of the same variable with different values? python

I am a complete newbie and this might be a dumb question: I need to make a list of the values as u can see down here. I will most likely need a for loop using append from what I have read till now but I cant really grasp how to do it in my case. I want to start with the min value 23 and increment by 2 until I reach the max 31 And I would need to be able to change the values in the for loop for future changes The +3 has to be added everytime regardless It would be great if someone could help me.

JavaScript

Advertisement

Answer

Instead of evaluating the + 3 and + 23 at each variable, you can use a loop, and directly add the numbers to the parameters of the loop:

JavaScript

So a is the starting value, b is the additional value, c is the number of variables and step is the increment amount.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement