Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have the attached code and am having a problem with the next part: Count the number of characters received, and stop displaying any text
I have the attached code and am having a problem with the next part:
Count the number of characters received, and stop displaying any text after it has shown exactly 3000 characters. Since your chunk size will not divide evenly into 3000, you will need to add some logic to ensure that exactly 3000 characters (no more, and no less) are displayed.
Continue to retrieve the entire document, count the total number of characters, and display (i.e., print) the total number of characters.
1 import urllib 2 import re 3 url raw_input('Enter the URL:') 4 req request (url) 5 while True: 6 try: counts dict() fhandurllib.urlopen (req) for line in fhand: words line.split) for word in words: 10 counts[word] counts.get(word,0) 1 12 13 14 15 16 17 print(counts) data - count.getlength(512) if(len (data)
Step 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