Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Session03 and 04 activities - #81

Merged
PythonCHB merged 23 commits into
UWPCE-PythonCert:masterfrom
kathrynegan:master
Oct 31, 2017
Merged

PythonCHB merged 23 commits into
UWPCE-PythonCert:masterfrom
kathrynegan:master

Conversation

@kathrynegan

Copy link
Copy Markdown

No description provided.

@PythonCHB

Copy link
Copy Markdown
Contributor

Kat -- you've been busy!

There is a lot here -- anything in particular you would like reviewed?

@kathrynegan

kathrynegan commented Oct 28, 2017 via email

Copy link
Copy Markdown
Author

@PythonCHB PythonCHB left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some really nice work!

Great to see you get into the projects.

'Benedict Cumberbatch': [200000.0],
'Elon Musk': [10000.0, 150000.0, 100000.0],
'Dad': [20.0, 5.0],
'Donald Trump': [2.81],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generous donor, that Trump guy :-)



def update_widths(line):
""" Updates minimum column widths based on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting fancy here! nice!

'Donald Trump': [2.81],
'Billy Neighbor': [.54, .01, .25]}

COLUMN_WIDTHS = [0] * 4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's worth having this as a global, rather than simply re-creating it when you need it.

options = {
'1': {
'prompt': 'Send a Thank You',
'module': print_thank_you},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably want to use the word "function" or "operation" or "action", or.... "module" has a specific meaning in Python.

nice structure though!

while True:
print('Please choose from the following options:')
prompt = '\n'.join(['{} {}'.format(
option, options[option]['prompt']) for option in options])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really slick!

one hint -- if you want both the key and the value in a dict, you can use items():

['{} {}'.format( option_num, option['prompt']) for option_num, option in options.items()]

print('\tSYSTEM RESULT: {}'.format(result))
print('\tANSWER: {}'.format(answer))
else:
print('passed {} module'.format(module.__name__))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got slicing down --nice work!



def pad(integer, length):
""" Pads given integer as string with 0s up to given length.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything in this lab can be done pretty directly with the right formatting specifier..

"""
if not tup:
return 'no numbers'
output = 'the {:d} numbers are: ' + ', '.join(['{:d}'] * len(tup))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

s4 = {i for i in range(21) if i % 4 == 0}
print('s2:{}'.format(s2))
print('s3:{}'.format(s3))
print('s4:{}'.format(s4))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when it's this simple -- not much need for the format string:

print("s4:", s4)


with open(path_to_file, 'r') as f:
f.readline()
for line in f.readlines():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for line in f:

does the same thing, but without loading it all into memory first.

@PythonCHB
PythonCHB merged commit bc32ca9 into UWPCE-PythonCert:master Oct 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants