Revert "Completed 10-8 Cats and Dogs"
This reverts commit d70f69744d1b93c9a7e96fc5fd2dbd22482320b1.
This commit is contained in:
parent
d70f69744d
commit
07f81d5b58
@ -1,25 +0,0 @@
|
|||||||
# Exercise 10-8 Cats and Dogs
|
|
||||||
# Learning Objective: Read from two files and include a try except section to catch file not found error.
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
cats = Path("./Chapter_10/cats.txt")
|
|
||||||
dogs = Path("./Chapter_10/dogs.txt")
|
|
||||||
combined_list = []
|
|
||||||
|
|
||||||
try:
|
|
||||||
cats_content = cats.read_text()
|
|
||||||
except FileNotFoundError:
|
|
||||||
print(f"Sorry, the file {cats} doesn't exist.")
|
|
||||||
else:
|
|
||||||
for name in cats_content.splitlines():
|
|
||||||
combined_list.append(name)
|
|
||||||
|
|
||||||
try:
|
|
||||||
dogs_content = dogs.read_text()
|
|
||||||
except FileNotFoundError:
|
|
||||||
print(f"Sorry, the file {dogs} doesn't exist")
|
|
||||||
else:
|
|
||||||
for name in dogs_content.splitlines():
|
|
||||||
combined_list.append(name)
|
|
||||||
print(combined_list)
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
Terry
|
|
||||||
Jones
|
|
||||||
Spooter
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
Frank
|
|
||||||
Chonk
|
|
||||||
Gonzo
|
|
||||||
Loading…
x
Reference in New Issue
Block a user