Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I've solved this problem to 98% the challenge I'm having is removing the comma when it is only two streaming service. Attached is a picture

I've solved this problem to 98% the challenge I'm having is removing the comma when it is only two streaming service. Attached is a picture of the question, my solution and the sample.txt and my test.txt and full_result.txt. You'll notice the only error I'm having is the comma within the streaming service.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

1 \#Write a function called write streaming info. 2 \#write streaming info will take as input two parameters: a 3 \#string and a list. 4 \# 6 \# 7 \#Each item in the list will be a tuple. The first item of 8 \#every tuple will be the name of a movie. All remaining items 9 \#in the tuple will be streaming services on which the movie 10 \#appears, such as Hulu, Netflix, Peacock, HBO Max, Amazon, 11 \#Disneyt, Peacock, YouTube, Crunchyroll, CBS All Access, etc. 12 \# 13 \#write streaming info should write the list of movies to the 14 \#file given by the filename using the following format: 15 \# 16 \# [movie]: Available on Service_1, Service_2, and Service_3 18 \#The movies and the streaming service names should appear in 19 \#the order of the original list/tuples. 20 \# 21#50, for this list of tuples: 22 \# 23 \# [("Chocolat", "Hulu", "Netflix", "Amazon"), 24 \# ("Skyfall", "HBO Max", "Amazon"), 25 \# ("Soul", "Disneyt")] 26 \# 26 \# 27 \#The file printed would look like this: 28 \# Chocolat: Available on Hulu, Netflix, and Amazon * Skyfall: Available on HBO Max and Amazon \# Soul: Disneyt \# \#Note that if only one service is listed, just that service \#appears after the colon. If two services are listed, they \#appear separated by 'and' with no commas. If three or more \#services are 11 sted, then there is a comma after every \#service except the last one, and the last one is preceded 35 \#appear separated by 'and' with no commas. If three or more 36 \#services are listed, then there is a comma after every 37 \#service except the last one, and the last one is preceded 38 \#by "and". 49 \# 41 \#HINT: Remember, you can use slicing on tuples just like strings. 42 \#a tuple[:2], for example, will give you the first two items in a 43 \#tuple. a tuple[3:] will give you all the items from the one at \#index 3 to the end. \#Below are some lines of code that will test your function. \#rou can change the value of the variable(s) to test your \#function with different inputs. \# \#If your function works correctly, this will originally 41 Hniwl: kememuer, you can use sticing on tuples just like scrirgs. 42 \#a tuple[:2], for example, will give you the first two items in a 43 \#tuple. a tuple[3:] will give you a11 the items from the one at 44 \#index 3 to the end. * Write your function here! def write streaming_info(filename, alist): file = open (filename, ' w ') for index, items in enumerate(alist): if len(items) 2: file.write(items [0]+: ') else: file. Write(items [0]+: ') for i in range (1, len ( items )) : if i==len(i tems ) or i==( len (i tems )1) : file. Write(items [i]) elif i=len(items)2: file.write(f" { items [i]} and ") file.write((ln)file.close() \#Below are some Tines of code that will test your function. 79 HYou can change the value of the variable(s) to test your 71 \#function with different inputs. 73 rif your function works correctly, this will originally 74 mprint nothing .. however, it should write the same contents Has sample, txt to Test.txt. 6 movies = [("Chocolat", "Hulu", "Netflix", "Amazon"), ("Skyfall", "HBO Max", "Amazon") ("Soul", "Disneyt")] Write_streaming_info("Test.txt", movies) Sample.txt 1 Chorolat: Hulu, Netflix, and Amazon 2 Sky tall: HBO Max and Amazon Soul: Disneyt 1 Chocolat: Hulu, Netflix and Amazon 2 Skyfal1: HBO Max and Amazon JSoul: Disneyt 1. We found the following problems with your submission: 32 We tested your code with filename = "AutomatedTest-OymXpo.txt", movies = [('Rocky IV', 'Peacock'), ('Home Alone', "Hulu', 'Amazon'), ('Robin Hood', 'Amazon', 'Crunchyrol1', 'CBS A11 Access', "YouTube', "HBO Max'), ("Wayne's World", 'Peacock', 'Netflix', 'Amazon') ]. We expected the file to contain this: 4 Rocky IV: Peacock 5 Home Alone: Hulu and Amazon 6 Robin Hood: Amazon, Crunchyro11, CBS All Access, YouTube, and HBO Max Wayne's World: Peacock, Netflix, and Amazon However, the file contained this: Rocky IV: Peacock Home Alone: Hulu, and Amazon Robin Hood: Amazon, Crunchyrol1, CBS All Access, YouTube, and HBO Max Wayne's world: Peacock, Netflix, and Amazon We tested your code with filename = "AutomatedTest-BZjEUQ.txt", movies = [( 'Pet Sematary', "YouTube"), ('Up in Smoke", 'YouTube', 'HBO Max', 'Crunchyroll' ), ('The Crying Game', "Amazon", 'Crunchyrol1', "YouTube'), ('Patch Adams', 'Disney+', 'Amazon', 'Netflix', 'CBS All Access', 'YouTube'), ('Medicine Man', 'CBS All Access', 'Hulu', 'HBO' Max', 'Peacock'), ('Arachnophobia', 'Peacock', 'HBO Max')]. We expected the file to contain this: 17 Pet Sematary: YouTube 18 Up in Smoke: YouTube, HBO Max, and Crunchyroll 19 The Crying Game: Amazon, Crunchyroll, and YouTube 20 Patch Adams: Disney+, Amazon, Netflix, CBS All Access, and YouTube 21 Medicine Man: CBS Al1 Access, Hulu, HBO Max, and Peacock Arachnophobia: Peacock and HBO Max However, the file contained this: Pet Sematary: YouTube Up in Smoke: YouTube, HBO Max, and Crunchyroll The Crying Game: Amazon, Crunchyroll, and YouTube Patch Adams: Disneyt, Amazon, Netflix, CBS All Access, and YouTube Medicine Man: CBS All Access, Hulu, HBO Max, and Peacock Arachnophobia: Peacock, and HBO Max

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago