From a595882196f9ba8ab256dc33acb1323c05981112 Mon Sep 17 00:00:00 2001 From: David Avery Date: Wed, 5 Feb 2020 14:09:20 +0000 Subject: [PATCH] Coding exercise 46 --- basics.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/basics.py b/basics.py index 8dbe163..9bcfb6a 100644 --- a/basics.py +++ b/basics.py @@ -1,5 +1,7 @@ -myfile = open("fruits.txt") -content = myfile.read(6) -myfile.close() +def countstring(character, filepath): + myfile = open(filepath) + content = myfile.read() + myfile.close() + return(content.count(character)) -print(content) \ No newline at end of file +print(countstring("a", "fruits.txt")) \ No newline at end of file