Whats up guys?

I need help my code is not working too great could someone please help me?
My Input should be : 03/12 hello there
My Output should be : March the 12th: hello there

It needs to work for January, February, March, April, May and June. And all dates the input date can be either "03/12" or " 03:12" and i should get the same output.

Here is my code:

def Program(month):

	if month == "01" :
		return "January"
	elif month == "02" :
		return "February"
	elif month == "03" :
		return "March"
	elif month == "04" :
		return "April"
	elif month == "05" :
		return "May"
	elif month == "06" :
		return "June"
month = raw_input()
Program(month)

def Program2(date):
	
	if date == "01" :
		return "1st"
	elif date == "02" :
		return "2nd"
	elif date == "03" :
		return "3rd"
	elif date == "04" :
		return "4th"
	elif date == "05" :
		return "5th"
	elif date == "06" :
		return "6th"
	elif date == "07" :
		return "7th"
	elif date == "08" :
		return "8th"
	elif date == "09" :
		return "9th"
	elif date == "10" :
		return "10th"
	elif date == "11" :
		return "11th"
	elif date == "12" :
		return "12th"
	elif date == "13" :
		return "13th"
	elif date == "14" :
		return "14th"
	elif date == "15" :
		return "15th"
	elif date == "16" :
		return "16th"
	elif date == "17" :
		return "17th"
	elif date == "18" :
		return "18th"
	elif date == "19" :
		return "19th"
	elif date == "20" :
		return "20th"
	elif date == "21" :
		return "21st"
	elif date == "22" :
		return "22nd"
	elif date == "23" :
		return "23rd"
	elif date == "24" :
		return "24th"
	elif date == "25" :
		return "25th"
	elif date == "26" :
		return "26th"
	elif date == "27" :
		return "27th"
	elif date == "28" :
		return "28th"
	elif date == "29" :
		return "29th"
	elif date == "30" :
		return "30th"
	elif date == "31" :
		return "31st"
date = raw_input()
Program2(date)

def Sign(Symbol) :
	if Symbol == ":" :
		return " the " 
Symbol = raw_input()
Sign(Symbol)

Activity = raw_input()
print Program(month) + " the " + Program2(date) + ":" + Activity

Your help would be much appreciated :)

Are you not allowed to use dict or int? You have names in capital letters but I do not see any class definitions (Capitals are reserved by convention for defining classes).

Could you explain how lines 85...90 (Python ranges are not including the last number ;)) work?

I would not also otherwise describe your code as intuitive or naming as intuitive, sorry to say.

I get by some kind of reverse polish notation (last line is the output):

04
28
/
Learn Python!
April the 28th:Learn Python!

You know how to use split, don't you?

str.split([sep[, maxsplit]])ΒΆ

Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements). If maxsplit is not specified, then there is no limit on the number of splits (all possible splits are made).

If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings (for example, '1,,2'.split(',') returns ). The sep argument may consist of multiple characters (for example, '1<>2<>3'.split('<>') returns ). Splitting an empty string with a specified separator returns .

If sep is not specified or is None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace. Consequently, splitting an empty string or a string consisting of just whitespace with a None separator returns [].

For example, ' 1 2 3 '.split() returns , and ' 1 2 3 '.split(None, 1) returns .

Even that is not needed: what is element 2 of the legal input?

What happens when you input

02/31 February has 28 days

Please take note of the datetime module, particularly datetime.date which can be used to print all kinds of date-related things (method strftime)

By the time you finish reading all that good documentation and get to this line of my post, you should be slapping yourself on the forehead and thinking "I should go read about the Python Standard Library before I try to re-invent a way to do something in Python."

date = raw_input()

from datetime import date
d = date(date)
a = d.strftime("%B the %dth: ")
Activity = raw_input()
print a, Activity

How do u make date a raw_input, so i can insert for example 03/12 Thanks!, and my output should read as March the 12th: Thanks!

Line 4 dies not make sense you are usung raw_inputted string as function and parameter to function.

You can try coding my style, I start with fixed input (like "03/12" in your case and get the function for processing to work first. then when program has no bugs I add functionality, say handle bad inputs "31/2" and "2/31" and only think little advance by putting separator not as single value

separator = '/'

but as there will be second alternative later so I put

separators = ('/', )

tuple with plural variable name.

date = raw_input()

from datetime import date
d = date(date)
a = d.strftime("%B the %dth: ")
Activity = raw_input()
print a, Activity

How do u make date a raw_input, so i can insert for example 03/12 Thanks!, and my output should read as March the 12th: Thanks!

As TonyJv says: Line 4 makes no sense. You have to pay attention to variable names. Once you have date = raw_input() on line 1, you immediately overwrite it with a module named date on line 3, then on line 4 you are doing something even stranger. raw_input() returns a string, so to create a date, you need to convert it (see below). Then to print it out, you would use strftime() See docs links in my prior post.

If you will insist that the user input the date in an exact format, then you can just use strptime() to convert the user input and let it fail if the format is wrong. If you want to accept many forms of input from the user (maybe '3/12' or '3:12' or '3-12') then you need to split the user string and create a date from the pieces. One way is to use split() from the re module: re.split() but I hesitated to tell you about that, since I'm afraid it might confuse you even more. I recommend the first option (insist that the input be in an exact format). You can check if ':' in input and use strptime based on that check: One format for the ':' sep and one for the '/' sep.

I hesitate to say this but there exist one code of mine in the code snippets that makes your job trivial, but if you use it, it is cheating. You could read it few times and use idea of mine, but code it yourself.

Whats the name of the code in the code snippets?

I thought to leave it to your effort to find it, at least to practice to search Daniweb properly. click my username and check what code snippets I have posted, it is one of the oldest ones I posted.

ok Thanks man!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.