Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Python Loop

Python Loop

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
pythontoolstutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Smaini Nurbs
    wrote on last edited by
    #1

    How to write a script that uses a control statement (such as FOR loops, WHILE loops, etc...) to print out 50 lines using variables as shown in Figure 1. Note that Line 3 is derived by adding Line 1 & 2. Line 4 is derived by adding Line 2 & 3 and so on… Line 1 : 1 Line 2 : 1 Line 3 : 2 Line 4 : 3 Line 5 : 5 Line 6 : 8 Line 7 : 13 Line 8 : 21 … … Figure1. Output from executed script :confused: Smaini

    M 1 Reply Last reply
    0
    • S Smaini Nurbs

      How to write a script that uses a control statement (such as FOR loops, WHILE loops, etc...) to print out 50 lines using variables as shown in Figure 1. Note that Line 3 is derived by adding Line 1 & 2. Line 4 is derived by adding Line 2 & 3 and so on… Line 1 : 1 Line 2 : 1 Line 3 : 2 Line 4 : 3 Line 5 : 5 Line 6 : 8 Line 7 : 13 Line 8 : 21 … … Figure1. Output from executed script :confused: Smaini

      M Offline
      M Offline
      Michael Hansen
      wrote on last edited by
      #2

      q = [0,1]
      for i in range(1,50):
      sum = q[0] + q[1]
      print 'Line %d : %d' % (i,sum)
      if i > 1:
      q = [ q[1], sum ]

      MBH

      S 1 Reply Last reply
      0
      • M Michael Hansen

        q = [0,1]
        for i in range(1,50):
        sum = q[0] + q[1]
        print 'Line %d : %d' % (i,sum)
        if i > 1:
        q = [ q[1], sum ]

        MBH

        S Offline
        S Offline
        Smaini Nurbs
        wrote on last edited by
        #3

        Ok thanks for your suggestion!! :-D

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups