Completed Exercise 10-3 Simpler Code
This commit is contained in:
parent
03d91eeb6e
commit
96321d9bba
@ -8,8 +8,8 @@ contents = path.read_text()
|
|||||||
|
|
||||||
print(contents)
|
print(contents)
|
||||||
|
|
||||||
lines = contents.splitlines()
|
#lines = contents.splitlines()
|
||||||
|
|
||||||
for line in lines:
|
for line in contents.splitlines():
|
||||||
print(line)
|
print(line)
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,8 @@ contents = path.read_text()
|
|||||||
|
|
||||||
#print(contents)
|
#print(contents)
|
||||||
|
|
||||||
lines = contents.splitlines()
|
#lines = contents.splitlines()
|
||||||
|
|
||||||
for line in lines:
|
for line in contents.splitlines():
|
||||||
print(line.replace('Python', 'C'))
|
print(line.replace('Python', 'C'))
|
||||||
|
|
||||||
|
|||||||
10
Chapter_10/10-03_simpler_code.py
Normal file
10
Chapter_10/10-03_simpler_code.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Exercise 10-3 Simpler Code
|
||||||
|
# Learning Objective: Simplify previously written code.
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
path = Path('./Chapter_10/pi_digits.txt')
|
||||||
|
contents = path.read_text()
|
||||||
|
|
||||||
|
for line in contents.splitlines():
|
||||||
|
print(line.lstrip().rstrip())
|
||||||
3
Chapter_10/pi_digits.txt
Normal file
3
Chapter_10/pi_digits.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
3.1415926535
|
||||||
|
8979323846
|
||||||
|
2643383279
|
||||||
Loading…
x
Reference in New Issue
Block a user