Submission of Assignment 02

Morning, again,

OK. I looked at the link and the book and am still a little lost. I get I need to access the correct string, indicate what sequence I want to format, and then what I want to format it to.

NEWS = 'Hi {friend}! I have {0} news! I won the raffle with number {1}!'
FNAME = 'Pat'
NTYPE = '*amazing*'
RNUM = 42
NEWS = NEWS.format({'1':'06d'})
EMAIL = NEWS.format(NTYPE, RNUM, friend = FNAME)

I also tried NEWS.format(1, 06d). I know I’m missing something very important.

Thank you.

KJ
From: Chad Heuschober [mailto:notifications@github.com]
Sent: Friday, September 12, 2014 9:31 PM
To: is210-2014-fall-02/is210_lesson_02
Cc: kevin.doles@spsmail.cuny.edu
Subject: Re: [is210_lesson_02] Submission of Assignment 02 (#10)


In formatted.py:

> @@ -6,3 +6,5 @@

>  FNAME = 'Pat'

>  NTYPE = '*amazing*'

>  RNUM = 42

> +NEWS = NEWS.format(

> +EMAIL = NEWS.format(friend = FNAME, NTYPE, RNUM)

Don't be so hard on yourself Kevin. You're actually doing really well. I make this homework challenging for a reason.

Using the modulus operator with a string (%) is the old-style formatting string. The author briefly discusses both but we're going to use the new style for this course.

The documentation for the official mini-language is here:

https://docs.python.org/2.7/library/string.html#format-specification-mini-language

It's pretty dense so let me help you out here by unpacking it a bit:

{X:Y}

X, in this case, is the variable you intend to replace. That might be a numeric index (eg, 0,1,2) or a named variable. You can see examples of both in the course text and in the link above.

Y, is the formatting string. (your 06d part) which roughly means 0-padded to 6 characters and must be a digit (integer).

—
Reply to this email directly or view it on GitHub<https://github.com/is210-2014-fall-02/is210_lesson_02/pull/10/files#r17509572>.