Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I don't know what I'm doing wrong. Please help. 7.8 LAB: Word frequencies (lists) Write a program that first reads in the name of an

I don't know what I'm doing wrong. Please help.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
7.8 LAB: Word frequencies (lists) Write a program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates. Ex: If the input is: input1 . csv and the contents of input1.csv are: hello, cat, man, hey, dog, boy, Hello, man, cat, woman, dog, Cat , hey, boy the output is: hello 1 cat 2 man 2 hey 2 dog 2 boy 2 Hello 1 woman 1 Cat 1 Note: There is a newline at the end of the output, and input1.csv is available to download. 247772 1680582 LAB ACTIVITY 7.8.1: LAB: Word frequencies (lists) 2 / 10 Downloadable files input1 . csv Download main.py Load default template...7.8 LAB: Word frequencies (lists) Write a program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates. Ex: If the input is: input1 . csv and the contents of input1.csv are: hello, cat, man, hey, dog, boy, Hello, man, cat, woman, dog, Cat, hey, boy the output is: hello 1 cat 2 man 2 hey 2 dog 2 boy 2 Hello 1 woman 1 Cat 1 Note: There is a newline at the end of the output, and input1.csv is available to download. 247772 1680582 LAB ACTIVITY 7.8.1: LAB: Word frequencies (lists) 2 / 10 Downloadable files input1 . csv Download main.py Load default template... import csvNote: There is a newline at the end of the output, and input1.csv is available to download. 247772.1680582 LAB ACTIVITY 7.8.1: LAB: Word frequencies (lists) 2/ 10 Downloadable files input1 . csv Download main.py Load default template... import csv 3 filename = input( ) 4 try: 6 reader = csv. reader (open(filename) ) 7 except: 8 print( ' Failed to read file' ) 9 exit ( ) 10 11 words = next (reader) 12 uniquewords = 13 14 for word in words: 15 if word not in uniquewords: 16 uniquewords . append(word) 17 18 for i in range (0, len (uniqueWords) ) : 19 print (words [i], words . count (uniqueWords [i] ) )| Develop mode Submit mode When done developing your program, press the Submit for grading button below. This will submit your program for auto-grading. Submit for grading Signature of your work What is this? 2/14 . . U---10--12-- -10-10-12-12-12 R--10- - 12-10 U- - 10- - -10- 11-11-12 ..2/21 Latest submission - 9:49 PM on 02/21/21 Total score: 2 / 10Signature of your work What is this? 2/14. . U---10--12------10-10-12-12-12 R--10----- - - - -12-10---- - - -- U-- 10------10- |1-|1-12 ..2/21 Latest submission - 9:49 PM on 02/21/21 Total score: 2 / 10 Only show failing tests Download this submission 1: Compare output 0 / 1 Output differs. See highlights below. Input inputl . csv hello 1 cat 2 man 2 hey 2 Your output dog 2 boy 2 Hello 1 man 1 cat 1 hello 1 cat 2 man 2 hey 2 Expected output dog 2 boy 2 Hello 1 woman 1 Cat 1 2: Compare output 0/ 22: Compare output ~ 0/2 Output differs. See highlights below. Special character legend Input input2 . csv bubble 3 caring 1 unsuitable 1 bubble le dispensable 1 obtainable 1 bloody 1 meddle 1 crown 1 visitor 1 ahead 1 invention 1 spot 1 delirious 1 Your output savory 1 servant 1 pot 1 increase 1 soothe 1 truculent 1 squeak 2 learn 1 troubled 1 bubble 14 walk 1 learn 24 tease 1 cumbersome 1 deeply 1 Screenshot saved spark 1 The screenshot was added to your OneDrive. bubble 3 OneDrive caring 1spark bubble 3 caring 1 unsuitable 1 dispensable 1 obtainable 1 bloody 1 meddle 1 crown 1 visitor 1 ahead 1 invention 1 spot 1 delirious 1 savory 1 Expected output servant 1 pot 1 increase 1 soothe truculent 1 squeak 1 learn 2 troubled 1 walk 1 tease 1 cumbersome 1 deeply 2 spark 1 science le island le narrow le 3: Compare output 0 /2 Output differs. See highlights below. Screenshot saved The screenshot was added to your Input input3 . csv OneDrive. OneDrive hi3: Compare output 0/2 Output differs. See highlights below. Input input3 . csv hi 7 Your output hi 2 hi 3 hey hi 7 Expected output hey 2 Hi 3 HI 4: Compare output 2/2 Input input4 . csv caring 1 unsuitable 1 bubble 1 dispensable 1 obtainable 1 bloody 1 meddle 1 crown 1 visitor 1 ahead 1 invention 1 spot 1 delirious 1 savory 1 Screenshot saved Your output servant 1 The screenshot was added to your pot 1 OneDrive. increase 1 OneDrive soothe 1Input input4 . CSV caring 1 unsuitable 1 bubble 1 dispensable 1 obtainable 1 bloody 1 meddle 1 crown 1 visitor 1 ahead 1 invention 1 spot 1 delirious 1 savory 1 servant 1 Your output pot 1 increase 1 soothe 1 truculent 1 squeak 1 learn 1 troubled 1 walk 1 tease 1 cumbersome 1 deeply 1 spark 1 science 1 island 1 narrow 1 5: Compare output 0/3 Output differs. See highlights below. Special character legendOutput differs. See highlights below. Special character legend Input input5 . csv spy 5 pleasure 1 uncovered 1 upbeat 1 found 1 copper 3 share 1 believe 1 brawny 1 committee 1 hydrant 1 spy le eminent 2 towering 1 coherent 1 past 2 hate 2 step 1 influence 1 ants 2 desk 1 obsolete 1 analyse 1 important 1 unruly 1 cowardly 1 amused 1 governor 1 sloppy 1 level 1 call 1 Screenshot saved transport 3 The screenshot was added to your cakes 1 OneDrive. bad 1 OneDrive numerous 1transport cakes 1 bad 1 numerous 1 march 1 murder 1 possessive 1 internal 1 Your output giant 1 hum 1 rose 1 aunt 1 skin 1 trouble 1 continue 1 glow 1 enchanting 1 sock 1 motionless 1 waste 1 marvelous 2 secretive 1 guarantee 1 ducks 1 top 1 flood 1 well-off 1 milk 1 bubble 1 magic 1 spray 1 spare 1 love 1 stereotyped 1 jagged 1 dysfunctional 1 sneeze mountain 1 ignore 24 tacky 1mountain 1 ignore 24 tacky 1 tacky 1 incompetent 1 secretive le dear 1 dare 1 caring 1 property 1 copper 1 spy 5 pleasure 1 uncovered 1 upbeat 1 found 1 copper 3 share 1 believe 1 brawny 1 committee 1 hydrant 1 eminent 1 towering 2 coherent 1 past 1 hate 2 step 2 influence 1 ants 1 desk 2 obsolete 1 analyse 1 important 1 unruly 1 Screenshot saved cowardly 1 The screenshot was added to your amused 1 OneDrive. governor 1 OneDrive sloppyobsolete 1 analyse 1 important 1 unruly 1 cowardly 1 amused 1 governor 1 sloppy 1 level 1 call 1 transport 1 cakes 3 bad 1 numerous 1 march 1 murder 1 possessive 1 internal 1 giant 1 Expected output hum 1 rose 1 aunt 1 skin 1 trouble 1 continue 1 glow 1 enchanting 1 sock 1 motionless 1 waste 1 marvelous secretive guarantee ducks 1 top 1 flood 1 Screenshot saved well-off 1 The screenshot was added to your milk 1 OneDrive. bubble 1 OneDrivesock 1 motionless 1 waste 1 marvelous 1 secretive guarantee ducks 1 top 1 flood 1 well-off 1 milk 1 bubble 1 magic 1 spray 1 spare 1 love 1 stereotyped 1 jagged 1 dysfunctional 1 sneeze 1 mountain 1 ignore 1 tacky 2 incompetent 1 dear 1 dare 1 caring 1 property 1 mist le test 1 foamy le notice le Screenshot saved 5 previous submissions The screenshot was added to your OneDrive. 7:44 PM on 2/21/21 1 / 10 OneDrive View

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

Write the difference between sexual and asexual reproduction.

Answered: 1 week ago

Question

What your favourite topic in mathematics?

Answered: 1 week ago