michael4227 / OIM3640-2021fall

Python
0 stars 0 forks source link

Exercise in Session 03 #2

Closed lzblack closed 2 years ago

lzblack commented 3 years ago

Good job!

Please use f-strings: https://github.com/michael4227/OIM3640/blob/d3c2fbb969c3b2f111c4a9f8803538852b5aa394/session03/calc_2.py#L23 https://github.com/michael4227/OIM3640/blob/d3c2fbb969c3b2f111c4a9f8803538852b5aa394/session03/calc_2.py#L26

michael4227 commented 2 years ago

Hi Professor, I just fixed this. Please let me know whether this is okay:) Thank you!

lzblack commented 2 years ago

https://github.com/michael4227/OIM3640/blob/caa034726dc67853736274c81005b69ff53bbdd1/session03/calc_2.py#L29-L30

You are still using .format() which can be replaced by using f-string. i.e.

var = (89-82)/82*100
print(f'{var:.2f}')
michael4227 commented 2 years ago

Got it, thank you professor! Here are my updates: var = '{:.2f}'.format((89-82)/82100) print(f'{var}%') or var = (89-82)/82100 print(f'{var:.2f}%')