Question

1 import urllib 2 import re 3 url raw_input(Enter the URL:) 4 req request (url) 5 while True: 6 try: counts dict() fhandurl

I have the attached code and keep getting an unexpected indent error on the last line, how can I fix this?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

import urllib
import re
url=input("Enter the URL:") #raw_input() became input() in python3
req=request(url)
while True:
try:
counts=dict()
fhand=urllib.urlopen(req)
for line in fhand:
words=line.split()
for word in words:
counts[word]=counts.get(word,0)+1
print(counts)
data=count.getlength(512)
if(len(data)<1):
break
print(data)
except: # I have added these two lines to remove the error
pass

Add a comment
Know the answer?
Add Answer to:
I have the attached code and keep getting an unexpected indent error on the last line,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have the current code that is working. I need to edit it so that I...

    I have the current code that is working. I need to edit it so that I am only counting strings that are after the word 'From' in a text file. Right now it's counting all words, but I just need the From email addresses in a text file. I think the issue if in the if/else loop but nothing I have tried works. Please help! 1 import string 2 fhand open('C: \Users \Brooke\Canopy scripts mbox-short.txt') 3 counts dict( 4 for...

  • Topic: Java Programming Hello, I have the following code attached below, and keep getting told that...

    Topic: Java Programming Hello, I have the following code attached below, and keep getting told that "Television" on the 23rd line "cannot be resolved to a type". It happens on this line of code... Television portable = new Television("Sharp", 19); Can you tell me how to fix this? Beginning of code... import java.util.Scanner; public class TelevisionDemo { {} public static void main(String[] args) { // //create a Scanner object to read from the keyboard Scanner keyboard = new Scanner(System.in); //...

  • I cant get this python program to read all the unique words in a file. It...

    I cant get this python program to read all the unique words in a file. It can only read the number of the unique words in a line. import re import string from collections import Counter # opens user inputted filename ".txt" and (w+) makes new and writes def main(): textname = input("Enter the file to search: ") fh = open(textname, 'r', encoding='utf-8' ) linecount = 0 wordcount = 0 count = {} print("Sumary of the", fh) for line in...

  • I am working on this code and keep getting errors like "ERROR: Syntax error: Encountered "<EOF>"...

    I am working on this code and keep getting errors like "ERROR: Syntax error: Encountered "<EOF>" at line 1, column 169." and "ERROR: Table/View 'STUDENT' does not exist. ERROR: Table/View 'STUDENT' does not exist. ERROR: Table/View 'STUDENT' does not exist." I do not know why this isn't working. Here is my code: DTCCDatabase.java import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /** * This program creates the CoffeeDB database. */ public class DTCCDatabase {    public static void main(String[] args)...

  • The following code has a problem with polymorphism. I keep getting a runtime error. Error: "An...

    The following code has a problem with polymorphism. I keep getting a runtime error. Error: "An unhandled exception of type System.InvalidCastException occured in polymorphism.exe" Apparently, I need one line of code to fix it. C# Code: class Sensor     {         private string sensorName;         public Sensor(string _name)         {             sensorName = _name;         }         public virtual void ActionType()         {             Console.WriteLine("Sensor Detect Nothing.");         } } class SmokeSensor : Sensor     {         private string type;...

  • "Function does not take 0 arguments". I keep getting this error for my last line of...

    "Function does not take 0 arguments". I keep getting this error for my last line of code: cout << "First Name: " << employee1.getfirstName() << endl; I do not understand why. I am trying to put the name "Mike" into the firstName string. Why is my constructor not working? In main it should be set to string firstName, string lastName, int salary. Yet nothing is being put into the string. #include<iostream> #include<string> using namespace std; class Employee {    int...

  • I keep getting the compilation error: pass the filename from command line arguement... Can you please...

    I keep getting the compilation error: pass the filename from command line arguement... Can you please tell me what im doing wrong? here is the code: import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ShipDemo { public static void main(String[] args) { String companyName; int num_ships, total_passengers=0, total_tonnage=0; Ship[] shipInventory; try { if(args.length == 1) { File file = new File(args[0]); Scanner fileScan = new Scanner(file); companyName = fileScan.nextLine(); num_ships = fileScan.nextInt(); shipInventory = new Ship[num_ships]; int n=0; String type,name;...

  • This is my code: import numpy as np import pandas as pd import sys from keras.models...

    This is my code: import numpy as np import pandas as pd import sys from keras.models import Sequential from keras.layers import Dense from sklearn.preprocessing import StandardScaler from keras.layers.normalization import BatchNormalization from keras.layers import Dropout file_full=pd.read_csv("/Users/anwer/Desktop/copy/FULL.csv") file_bottom=pd.read_csv("/Users/anwer/Desktop/copy/bottom.csv") train=[] train_targets=[] test=[] test_targets=[] p=[] q=[]    # We will generate train data using 50% of full data and 50% of bottom data. #is train target for labeling ? yes for train data train_df = file_full[:len(file_full)//2] labels=[ 0 for i in range(len(file_full)//2)] train_df=train_df.append(file_bottom[:len(file_bottom)//2]) for...

  • Hey I have a task which consists of two part. Part A asks for writing a...

    Hey I have a task which consists of two part. Part A asks for writing a program of WORD & LINE CONCORDANCE APPLICATION in python which I have completed it. Now the second part has given 5 dictionary implementation codes namely as: (ChainingDict, OpenAddrHashDict with linear probing, OpenAddrHashDict with quadratic probing, and 2 tree-based dictionaries from lab 12 (BST-based dictionary implementation) and asks for my above program WORD & LINE CONCORDANCE APPLICATION  to use these implemented code and show the time...

  • I am using python3.6 and i am getting an error on line 42 num = int(fin.readline())...

    I am using python3.6 and i am getting an error on line 42 num = int(fin.readline()) #reading first value valueError: invalid literal, for int() with base 10 Any help is appreciated, here is the code. reads from txt file a few integers in an array and sorts them. thank you! # Function to do insertion sort def insertionSort(arr):     # Traverse through 1 to len(arr)     for i in range(1, len(arr)):         key = arr[i]         # Move elements of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT