[Tutor] Testing print
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Oct 1 03:02:23 EDT 2016
On 01/10/16 05:24, boB Stepp wrote:
> ===============================================================================
> '''Exerise 3.1 from "Think Python 2" by Allen Downey.
>
> This module will take a string and right justify it so that the last character
> of the line will fall in column 70 of the display. The results will be
> printed to stdout.'''
>
> def right_justify(a_string):
<snip>
> def print_msgs(*msgs):
> '''Prints messages to stdout.'''
>
> for msg in msgs:
> print(msg)
>
> def main(input_strings):
> '''Run main program.'''
>
> print('0123456789' * 7) # Print a number guide to check length of line.
> for input_string in input_strings:
> print_msgs(*right_justify(input_string))
Do you need print_msgs()?
Won't it work the same with
print(right_justify(input_string))
You are only feeding one line at a time into the print msgs.
You could do it all in a new print_msgs() like:
def print_msgs(formatter, msgs):
for msg in msgs:
print(formatter(msg))
And main() reduces to
def main():
print_msgs(right_justify, input_strings)
But I think I'd just leave it as you have it but
without the print_msgs()...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list