Skip to content

Instantly share code, notes, and snippets.

@mtdukes
Last active May 11, 2017 19:18
Show Gist options
  • Select an option

  • Save mtdukes/4d43fba765c207724c33e031e0cffc78 to your computer and use it in GitHub Desktop.

Select an option

Save mtdukes/4d43fba765c207724c33e031e0cffc78 to your computer and use it in GitHub Desktop.
A simple program to run from the command line
#import a python library to help us work with dates and times
import datetime
# define a FUNCTION to run a specified task
def main():
print 'Hello World!'
print 'I am some prepackaged code.'
print "I don't do much, but I'm still special!"
# another function, but we won't run this at first
# this function accepts two arguments it will use to perform its task
def add_two_things(x, y):
print '\nIt looks like you want to add '+str(x)+' and '+str(y)+'!'
print 'I can do that!'
print 'The sum is:'
print x + y
# Use the datetime library to get the current date
# Then check to see if it's morning or afternoon
def get_date():
print '\nThe current date and time is: '
print datetime.datetime.now()
if datetime.datetime.now().time() < datetime.time(12):
print "It's the morning!"
else:
print "It's the afternoon!\n"
# it's good practice to use this bit of code
# when you're writing scripts you plan to run
if __name__ == '__main__':
#run the function we defined earlier
main()
add_two_things(20,17)
get_date()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment