Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Exercises #226

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
df8388c
Add codingbat exercises and homework assignments
Oct 31, 2018
0c507f1
Add slicing_lab
Oct 31, 2018
33a37dd
Update slicing lab
Oct 31, 2018
7600d41
Add completed list lab exercise
Oct 31, 2018
db7eccf
Add mailroom 1 exercise
Nov 28, 2018
6f28b25
Update code to meet PEP8 style standards
Nov 28, 2018
5594b91
Add completed str formatting lab
Nov 28, 2018
9644162
Update to meet PEP8 style standards
Nov 28, 2018
9502c8d
resolving merge conflict
Nov 28, 2018
9070037
Resolve merge conflicts
Nov 28, 2018
a07f102
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
Dec 9, 2018
dc5341c
Add homework files to personal cloned repository
Dec 9, 2018
978f679
Add dict set lab to student repo
Dec 9, 2018
f7d658a
Add paths and file processing exercise
Dec 9, 2018
23512cc
Add file and processing exercise
Dec 10, 2018
bbede62
Add mailroom 2
Dec 11, 2018
27a56c0
Refactoring mailroom 1 exercise
Dec 11, 2018
f2a3621
Add recent changes to mailroom
Dec 12, 2018
c4979ad
Refactor mailroom with dicts
Dec 12, 2018
57fe3da
Add mailroom 2 refactor. Create report needs work still.
Dec 12, 2018
592133a
Completed mailroom2 refactor
Dec 12, 2018
e62eac9
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
Dec 12, 2018
b450ac9
Update to meet pycodestyle
Dec 13, 2018
8fe54ee
Remove whitespace to meet pycodestyle
Dec 13, 2018
786696f
Add session05 exercises
Dec 13, 2018
1e508d8
Update gitignore to include .csv file extensions
Dec 13, 2018
6027e9c
Update gitignore to include .txt files
Dec 13, 2018
cd797e7
Completed exceptions exercise
Dec 13, 2018
ca54533
Add exceptions lab
Dec 13, 2018
c5565ea
Completed safe_input exceptions lab
Dec 13, 2018
9be136a
Completed cigar_party test excercise
Dec 13, 2018
8283d04
Add unit testing for make_chocolate codindbat
Dec 13, 2018
02feb90
Completed dict set lab with comprehensions
Dec 14, 2018
8cbe009
Completed args kwargs lab
Dec 17, 2018
14578f7
Fixed syntax error
Dec 17, 2018
1826882
Update function name
Dec 17, 2018
367e142
Fix NameErrors to pass pytest
Dec 17, 2018
319e4b3
Fix unindentation
Dec 17, 2018
6a5e524
Fix unindentation
Dec 17, 2018
9147e42
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
Dec 17, 2018
394fc63
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
Dec 17, 2018
700389c
Add mailroom 4 to student repo still wip
Dec 17, 2018
2e98045
Merge branch 'master' of https://github.com/UWPCE-PythonCert-ClassRep…
Dec 17, 2018
104ef25
Add mailroom 4 and testing
Dec 17, 2018
bb7374f
Update typo
Dec 17, 2018
5c56b53
Adding Mailroom 4 and html render assignment
Dec 17, 2018
fe6c586
Add html render exercise to student repo
Dec 17, 2018
3e0f84f
Reworked html to pass tests
Dec 17, 2018
12fb4cf
Completed circle exercise
Dec 17, 2018
43a8d0f
Add code for tests to pass
Dec 18, 2018
8632a29
Refactored code to pass tests
Dec 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add completed str formatting lab
Fyfy Nguyen committed Nov 28, 2018
commit 5594b912f1c08c240a486ecfd7899423bf41b666
54 changes: 54 additions & 0 deletions students/FyfyNguyen/session03/strformat_lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

"""
String formatting lab
"""

# Task One
print("file_{:03d}: {:.2f}, {:.2e}, {:.3e}".format(
2, 123.4567, 10000, 12345.67))

# Task Two
tup = 2, 123.4567, 10000, 12345.67

# old style
print("file_00%d: %.2f, %.2e, %.3e" % (tup[0], tup[1], tup[2], tup[3]))

# f-string
print(f"file_{tup[0]:03d}: {tup[1]:.2f}, {tup[2]:.2e}, {tup[3]:.3e}")


# Task Three
# Format arbitrary object just using {}
# Multiply a list by length of the sequence to get number of "{}" needed
# Use str.join() method to join seq separated by commas
def formatter(seq):
seq_len = len(seq)
string = ("the {} numbers are: " + ", ".join(["{}"]*seq_len)).format(
seq_len, *seq)
return string.format(*seq)

# Task Four
print(formatter((4, 30, 2017, 2, 27)))

num = (4, 30, 2017, 2, 27)
print("{:02d} {} {} {:02d} {}".format(num[3], num[4], num[2], num[0], num[1]))

# Task Five
fruit = ['oranges', 1.3, 'lemons', 1.1]
print(f"The weight of an {fruit[0][0:-1]} is {fruit[1]} and the weight of a {
fruit[2][0:-1]} is {fruit[3]}")

print(f"The weight of an {fruit[0][0:-1].upper()} is {fruit[1] * 1.2} and the "
"weight of a {fruit[2][0:-1].upper()} is {fruit[3] * 1.2}")

# Task Six
data = [("Beyonce", 37, 355.00),
("Jay-Z", 48, 810.00),
("Blue Ivy", 6, 1, 165.00)
]

print("{:20s} | {:5s} | {:8s}".format("Name", "Age", "Price"))
print("-" * 42)
for item in data:
print("{:20s} {:5d} $ {:8,.2f}".format(*item))