Scripting for run same Python code 20-40 times (corresponding to different slices)

Thanks @mwestphal for your help. Could you please share some link or video to include the looping ?