Skip to content

Instantly share code, notes, and snippets.

@bmontana
Last active October 11, 2017 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmontana/3d1ce67cc6cc6f107b6481f803a5616a to your computer and use it in GitHub Desktop.
Save bmontana/3d1ce67cc6cc6f107b6481f803a5616a to your computer and use it in GitHub Desktop.
Redo dateconvert2.py using string formatting
# U05_Ex01_DateConvert2.py
#
# Author: Bill Montana
# Course: Coding for OOP
# Section: A3
# Date: 30 Oct 2017
# IDE: Pythonista for iOS
#
# Assignment Info
# Exercise: 1
# Source: Python Programming
# Chapter: 5
#
# Program Description
# Redo dateconvert2.py using string formatting
#
# Algorithm (pseudocode)
#
#
def main():
# get date
dateStr = input('Enter a date (mm/dd/yyyy): ')
# split into components
monthStr, dayStr, yearStr = dateStr.split('/')
# convert monthStr to the month name
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', ' September', 'October', 'November', 'December']
monthStr = months[int(monthStr)-1]
# output result in month day, year format
print('The converted date is {0} {1}, {2}'.format(monthStr, dayStr, yearStr))
main()
@bmontana
Copy link
Author

bmontana commented Oct 11, 2017

The only line changed is the print() statement at the end. We previously have learned this method to format output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment