[Tutor] how to write a function
Bartruff, Pamela J.
Pamela.J.Bartruff at supervalu.com
Mon Mar 24 16:17:01 CET 2008
Thank you so much. I appreciate the help, I am very new to Python, but
I would very much like to learn more...
From: bhaaluu [mailto:bhaaluu at gmail.com]
Sent: Monday, March 24, 2008 9:17 AM
To: Bartruff, Pamela J.
Cc: tutor at python.org
Subject: Re: [Tutor] how to write a function
On Mon, Mar 24, 2008 at 8:07 AM, Bartruff, Pamela J.
<Pamela.J.Bartruff at supervalu.com> wrote:
> Hello Python users,
> I am very new to Python, how do I program that converts 24 hour time
> hour time? The program should have three functions(input, conversion
> output function)
> Thanks for any help
> Pamela Bartruff
> Tutor maillist - Tutor at python.org
You define a function with: def functionName():
The body of the function should be indented (4 spaces is good).
So here are examples of 3 'stub' functions that don't do anything (yet):
# comments go after a hash
# this is the input function
varName = raw_input("Enter input: ")
# this is the conversion function
# do something here
# this is the output function
print ("You input %s" % varName)
varName = input()
if __name__ == "__main__":
You'll have to fill in the parts specific to your problem.
The best way to start is to work the problem out on paper
first: ie. you should already know how to do the math to
convert from 24 hour time, to 12 hour time. If you can't
do it on paper yet, you need to start by learning how to do it
on paper before you can teach the computer how to do it.
b h a a l u u at g m a i l dot c o m
"You assist an evil system most effectively by obeying its
orders and decrees. An evil system never deserves such
allegiance. Allegiance to it means partaking of the evil.
A good person will resist an evil system with his or her
whole soul." [Mahatma Gandhi]
More information about the Tutor