Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Run Lines of Code Multiple Times

  1. Feb 13, 2016 #1
    In Python 3...

    I have a few lines of code that I want the user to choose how many times it will run. For example:

    times=int(input())

    'times' will be the number of times the lines of code will run.

    How do I do it?
     
  2. jcsd
  3. Feb 13, 2016 #2

    Samy_A

    User Avatar
    Science Advisor
    Homework Helper

  4. Feb 13, 2016 #3
  5. Feb 13, 2016 #4

    Samy_A

    User Avatar
    Science Advisor
    Homework Helper

    Code (Python):
    times=int(input())
    myrange=range(0,times)
    for count in myrange:
        yourFirstLineOfCode
        yourSecondLineOfCode
        yourThirdLineOfCode
        youGetTheIdea
    print("Code has been executed the requested number of times")
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Run Lines of Code Multiple Times
  1. Running a Fortran code (Replies: 4)

Loading...