0
TEST VALUE:HELP (python)
i wrote quiet a long code(about 300 lines) in which a starting value goes through many calculations and functions, and eventually the result is printed. is there a way to run all the code with a given value '1' ,and print the result ,and immediately after re-do all the calculations as if the starting value was '2',and then print this second result too?
5 odpowiedzi
+ 5
you can use a for loop to run your code with several numbers. If numbers should run in sequence like 1,23,... you can use a range object with for loop like:
for i in range(1,21): -> this will run the code with numbers of 1 upto and including 20.
I you want to run just some numbers that do not fall in sequence, put them in a list first. then run for loop:
lst =[1,5,7,15,16]
for i in lst: -> this will run the code with all of the numbers from the list.
# your code runs here...
+ 1
this way, however, i would have to space every line i wrote till now, and certainly i could, but they are more than 300 and it would take a long time. i was looking for a quicker way of doing it
Thanks anyway
+ 1
(of course i could have thought ahead and spaced every line while writing it)
0
thanks, i still have to get to that lesson though