Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repeating a block of code
#6
I think this is what buran is suggesting.

This single line of code will repeat any code (indented by 4 spaces) below this line x10 times. Due to the way Python works, there is no need to close the loop with any code, the interpreter executes all indented code below the initial statement.

for x in range(10):
    Your code that you want repeated x10 should go here (note indentation)
    This line will also execute x10

This line is not indented and therefore will not execute x10
There may be other ways of doing this but this solution is short and in a single line.

Let me know if this is not what you want.

Good Luck

Bass

"The good thing about standards is that you have so many to choose from" Andy S. Tanenbaum
Reply


Messages In This Thread
Repeating a block of code - by owdcoder - Jun-11-2017, 02:52 PM
RE: Repeating a block of code - by Bass - Jun-11-2017, 02:58 PM
RE: Repeating a block of code - by buran - Jun-11-2017, 03:03 PM
RE: Repeating a block of code - by owdcoder - Jun-11-2017, 03:57 PM
RE: Repeating a block of code - by wavic - Jun-11-2017, 05:36 PM
RE: Repeating a block of code - by Bass - Jun-11-2017, 05:48 PM
RE: Repeating a block of code - by Larz60+ - Jun-11-2017, 07:27 PM
RE: Repeating a block of code - by RodNintendeaux - Jun-12-2017, 12:01 AM
RE: Repeating a block of code - by nilamo - Jul-14-2017, 03:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is 2/3 not just .666 repeating? DocFro 4 884 Dec-12-2023, 09:09 AM
Last Post: buran
  python multiple try except block in my code -- can we shorten code mg24 10 6,892 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE
  repeating a user_input astral_travel 17 2,643 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  if else repeating Frankduc 12 2,858 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  "If Len(Word) == 0" Code Block in Pig Latin Program new_coder_231013 3 2,220 Jan-02-2022, 06:03 PM
Last Post: deanhystad
  Try,Except,Else to check that user has entered either y or n (Code block pasted) RandomNameGenerator 3 2,442 Jun-29-2021, 08:21 PM
Last Post: RandomNameGenerator
  Repeating lines of code by an input Josh_Albanos 3 2,555 Oct-15-2020, 01:04 AM
Last Post: deanhystad
  factorial, repeating Aldiyar 4 2,974 Sep-01-2020, 05:22 PM
Last Post: DPaul
  Block of code, scope of variables and surprising exception arbiel 8 3,622 Apr-06-2020, 07:57 PM
Last Post: arbiel
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 7,076 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020