From 96321d9bbaa5d3313797e787cbc3ff029d8b6ee1 Mon Sep 17 00:00:00 2001 From: cheeks <134818917+leftovertoast@users.noreply.github.com> Date: Mon, 3 Mar 2025 18:11:26 +0000 Subject: [PATCH] Completed Exercise 10-3 Simpler Code --- Chapter_10/10-01_learning_python.py | 4 ++-- Chapter_10/10-02_learning_c.py | 4 ++-- Chapter_10/10-03_simpler_code.py | 10 ++++++++++ Chapter_10/pi_digits.txt | 3 +++ 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 Chapter_10/10-03_simpler_code.py create mode 100644 Chapter_10/pi_digits.txt 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