Question
I need help! Challenge Read a Text File You will be passed a file path P and string S on the command line. Output the
I need help!
Challenge
Read a Text File You will be passed a file path P and string S on the command line. Output the number of times the string S appears in the file P.
Here is what I have:
# Load our command line arguments import sys P= sys.argv[1] S= sys.argv[2] count = 0 # Your code goes here
#opening file at p with open(P) as f: #splitting the lines lines = f.read().split() w = 0 #iterating over lines for i in lines: #if the word matches increment count by 1 if lines[w] == S: count += 1 w+=1 #print all the words and count print("Count of \"%s\" is %d" %(S,count))
# Load our command line arguments inport sys CollpseText Files 4 P sys.argv[1 5 S sys.argvt2 4.3. Challenge: reading a text file count Your code goes here Read a Text File 9opening file at p with open(P) as f: splitting the lines ines-f.read).split() You will be passed a fle path P and string s on the command line Output the number of times the strings appears in the le 12 3 iterating over lines for tn lines : AST RUNon 2 23/2017 10 48 34AM if the word matches increment count by Program Output count1 print all the words and count Program Failed for Input content/extleslempty bxt parro Expected Output Your Program Ovtput Count of "parrot is print("Count of \"%s\" ?s %d" %(s,count)) Your output was incorrect Try againStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started