diff --git a/Chapter_10/10-01_learning_python.py b/Chapter_10/10-01_learning_python.py index 48b3dea..d6957c9 100644 --- a/Chapter_10/10-01_learning_python.py +++ b/Chapter_10/10-01_learning_python.py @@ -8,8 +8,8 @@ contents = path.read_text() print(contents) -lines = contents.splitlines() +#lines = contents.splitlines() -for line in lines: +for line in contents.splitlines(): print(line) diff --git a/Chapter_10/10-02_learning_c.py b/Chapter_10/10-02_learning_c.py index 2fdeb5a..ee04074 100644 --- a/Chapter_10/10-02_learning_c.py +++ b/Chapter_10/10-02_learning_c.py @@ -8,8 +8,8 @@ contents = path.read_text() #print(contents) -lines = contents.splitlines() +#lines = contents.splitlines() -for line in lines: +for line in contents.splitlines(): print(line.replace('Python', 'C')) diff --git a/Chapter_10/10-03_simpler_code.py b/Chapter_10/10-03_simpler_code.py new file mode 100644 index 0000000..092ee09 --- /dev/null +++ b/Chapter_10/10-03_simpler_code.py @@ -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()) \ No newline at end of file diff --git a/Chapter_10/pi_digits.txt b/Chapter_10/pi_digits.txt new file mode 100644 index 0000000..f77db0c --- /dev/null +++ b/Chapter_10/pi_digits.txt @@ -0,0 +1,3 @@ +3.1415926535 +8979323846 +2643383279