Trouble using "return" in python.

Discussion in 'Programming General' started by kmjt, Nov 14, 2010.

Trouble using "return" in python.
  1. Unread #1 - Nov 14, 2010 at 1:20 AM
  2. kmjt
    Joined:
    Aug 21, 2009
    Posts:
    14,450
    Referrals:
    8
    Sythe Gold:
    449

    kmjt -.- The nocturnal life chose me -.-
    Banned

    Trouble using "return" in python.

    Here's the question:

    Write a program that reads a string from the keyboard containing a date in the form mm/dd/yyyy and prints out the date in the form Month, Date, Year (See samples below). Your main function should handle all input from the user and printing. You should have another function, convertDate that takes the user input as an argument and returns the converted date string when called. Sample output below:

    Please enter a date (format:mm/dd/yyyy):02/11/1995
    Converted: February, 11, 1995.


    I think i'm mostly done however what I don't get is how to take the user as an argument and return the converted date string when called.. as said in the question printing must all be done in the main function.

    Here is my code:

    Code:
    def main():
        date = raw_input("Please enter a date (format: mm/dd/yyyy): ")
        datetest = date.split("/")
    
        if datetest[0] == "01":
            print "Converted: January,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "02":
            print "Converted: February,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "03":
            print "Converted: March,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "04":
            print "Converted: April,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "05":
            print "Converted: May,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "06":
            print "Converted: June,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "07":
            print "Converted: July,", datetest[1] + ",", datetest[2]
        
        elif datetest[0] == "08":
            print "Converted: August,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "09":
            print "Converted: September,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "10":
            print "Converted: October,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "11":
            print "Converted: November,", datetest[1] + ",", datetest[2]
    
        elif datetest[0] == "12":
            print "Converted: December,", datetest[1] + ",", datetest[2]
    
        else:
            print "Invalid date entered."
        
    def convertDate():
     
    
    main()
    
     
  3. Unread #2 - Nov 14, 2010 at 3:27 AM
  4. plzmike
    Joined:
    Nov 13, 2010
    Posts:
    12
    Referrals:
    0
    Sythe Gold:
    0

    plzmike Newcomer

    Trouble using "return" in python.

< Svchost.exe has encountered a problem | Wanting to make an open source bot. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site