def cleanedup(s):
alphabet = 'abcdefghijklmnopqrstuvwxyz#'
cleantext = ''
for character in s.lower():
if character in alphabet:
cleantext += character
else:
cleantext += ' '
return cleantext
linecount=0
maxlength=0
with open('elon-musk.txt') as text:
for line in text:
linecount+=1
length=len(line.split())
if length>maxlength:
maxline=line
maxlength=length
print('number of tweets:',linecount)
print('Tweet with max number of words:', maxline)
tweets={}
with open('elon-musk.txt') as text:
for line in text:
for word in cleanedup(line).split():
if "#" in word:
if word in tweets:
tweets[word] += 1
else:
tweets[word]= 1
while True:
word= input('enter hashtag:')
if word in tweets:
print('mentioned:',tweets[word],'times')
else:
print('not mentioned.')
def cleanedup(s): alphabet = 'abcdefghijklmnopqrstuvwxyz#' cleantext = '' for character in s.lower(): if character in alphabet: cleantext += character else: cleantext += ' ' return cleantexthashtag_words = []occurrences = []with open('elon_musk.txt') as book: for line in book: for i in line.split(): if "#" in i: i = i.replace('#','') hashtag_words.append(i) for i in range(len(hashtag_words)): words = hashtag_words[i] occurrences.append(words)while True: word = input('Enter word:') word = word.replace('#','') if word in occurrences: print('Mentioned', occurrences.count(word), 'times') else: print('Not mentioned.')
For my computer class I have to create a program that deals with
making and searching tweets. I am done with the program but keep
getting the error below when I try the first option in the shell.
Can someone please explain this error and show me how to fix it in
my code below? Thanks!
twitter.py - C:/Users/Owner/AppData/Local/Programs/Python/Python38/twitter.py (3.8.3) File Edit Format Run Options Window Help import pickle as pk from Tweet import Tweet import os def show menu():...
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...
hello good night, could you help me to see what is wrong with my
code, two errors appear at the bottom in red:
In [47]: file_contents-open("color-blanco.png") def calculate_frequencies (file_contents): # Here is a list of punctuations and uninteresting words you can use to process your text punctuations = ""!()-[]{};:"",-./?@#$%^&*_~ uninteresting_words = ["the","in" ,"a", "to", "if", "is", "it", "of", "and", "or", "an", "as", "i", "me", "my", "we", "o # LEARNER CODE START HERE result={} a-file_contents.split() for word in a: if word...
Please help!! These are the errors I'm getting ...
string_2_set - << Back Log out 1-def string_2_set(str): 2 Given a string, split it into words (based on whitespace). For each word, remove the first and last letters from the word, and insert the pair (as a two-character word) into the set. d = set() #empty set str2 -str , split(" ") #split string with space first = str2[0][0] + str2[0] [len(str2[0])-1] #first pair if(len(str2[1]) > 1): If any word is...
Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...
python programming: Can you please add comments to describe in detail what the following code does: import os,sys,time sl = [] try: f = open("shopping2.txt","r") for line in f: sl.append(line.strip()) f.close() except: pass def mainScreen(): os.system('cls') # for linux 'clear' print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print(" SHOPPING LIST ") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("\n\nYour list contains",len(sl),"items.\n") print("Please choose from the following options:\n") print("(a)dd to the list") print("(d)elete from the list") print("(v)iew the...
CAN SOMEONE PLEASE EXPLAN FO ME WHATS WRONG WITH MY CODE WHEN EVEN I RUN IT IT GIVE ME THIS MASSAGE IM USING python BTW Traceback (most recent call last): File "../resource/asnlib/public/RUN.py", line 20, in <module> exec(source_code, dict()) File "<string>", line 60, in <module> NameError: name 'total_rough_sod' is not defined ) from math import pi length = float(input('Enter Course Length:')) width = float(input('Enter Course Width:')) def calculate_smooth_sod(width): grean_area_raduis= (width/2)/2 total_smooth_sod=2*pi*(grean_area_raduis**2) return total_smooth_sod def calculate_sand_trap_area(width): sand_trap_radius=(width/3)/2 sand_trap_area=pi*(sand_trap_radius**2) return sand_trap_area def calculate_rough_sod(length,...
Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...
Can someone help me out with this? You are given a program that receives four lines in the below format, and stores them in str1, str2, str3, and num1. This is not a very long sentence. is long 4 Expand this program to: Write an if-elseif-else statement to print this line only if num1 is higher than 0: "Num1 is higher than 0!" print this line only if num1 is 0: "Num1 equals to 0!" And otherwise, print: ""Num1 is...
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...