[Tutor] how to insert a string?

andrade1@umbc.edu andrade1 at umbc.edu
Fri Sep 23 00:32:29 CEST 2005


I would like to insert a string into the following program to simplify the
program. Any suggestions on how I might do so?

# dateconvert2.py
#    Converts day month and year numbers into two date formats

import string

def main():
    # get the day month and year
    day, month, year = input("Please enter the day, month and year
numbers: ")

    date1 = str(month)+"/"+str(day)+"/"+str(year)

    months = ["January", "February", "March", "April",
              "May", "June", "July", "August",
              "September", "October", "November", "December"]
    monthStr = months[month-1]
    date2 = monthStr+" " + str(day) + ", " + str(year)

    print "The date is", date1, "or", date2


More information about the Tutor mailing list