Web Analytics Made Easy -
StatCounter New to Python I am trying to Create a loop to print the month number and name - CodingForum

Announcement

Collapse
No announcement yet.

New to Python I am trying to Create a loop to print the month number and name

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • New to Python I am trying to Create a loop to print the month number and name

    Can anyone out there help a novice out I am trying to Create a loop to print the month number and name


    pseudo code
    Months = [“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”]
    For x in range (1, 13)
    Do loop x in list.
    Print (“month {0} is {1}” Format X , month[x-1]
    End loop



    Months = [“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”]
    For x in range (1, 13)
    Print (“month {0} is {1}” Format X , month[x-1]
    Last edited by mcgraw927; Sep 19, 2019, 12:47 AM.

  • #2
    I'm an absolute novice too but heres nothing:
    PHP Code:
    # This Python file uses the following encoding: utf-8
    months = ["January""February""March""April""May""June""July""August""September""October""November""December"]
    for 
    x in range (12):
        print( 
    "Element Index["x"] Month "months[x] ) 
    Don't use old mysql library
    The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets
    When a white horse is not a horse

    Comment


    • #3
      The code is following for your solution :
      Code:
      Months = ['January','February','March','April','May','June','July','August','September','October','November',' December']
      for i in range (12):
      print( "Element Index[", i, "] Month ", Months[i] )
      You can also use the map function to reduce the code :

      Code:
      Months = ['January','February','March','April','May','June','July','August','September','October','November',' December']
      print ("Months : ", '%s' % ', '.join(map(str,Months)))
      ASP.Net Software Development

      Comment

      Working...
      X