I need Python help. The problem I am trying to figure out so that when we work a similar problem in class I can do my assignment.  Tonights assignment is a participation thing, Friday I need to do a similar assignment in class for a grade.                                                                                                                                                                       Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements: Each row contains the title, rating, and all showtimes of a unique movie. A space is placed before and after each vertical separator ('|') in each row. Column 1 displays the movie titles and is left justified with a minimum of 44 characters. If the movie title has more than 44 characters, output the first 44 characters only. Column 2 displays the movie ratings and is right justified with a minimum of 5 characters. Column 3 displays all the showtimes of the same movie, separated by a space. Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows. Ex: If the input of the program is: movies.csv and the contents of movies.csv are: 16:40,Wonders of the World,G 20:00,Wonders of the World,G 19:00,Journey to Space,PG-13 12:45,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 15:00,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 19:30,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 10:00,Adventure of Lewis and Clark,PG-13 14:30,Adventure of Lewis and Clark,PG-13 19:00,Halloween,R the output of the program is: Wonders of the World | G | 16:40 20:00 Journey to Space | PG-13 | 19:00 Buffalo Bill And The Indians or Sitting Bull | PG | 12:45 15:00 19:30 Adventure of Lewis and Clark | PG-13 | 10:00 14:30 Halloween | R | 19:00

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need Python help. The problem I am trying to figure out so that when we work a similar problem in class I can do my assignment.  Tonights assignment is a participation thing, Friday I need to do a similar assignment in class for a grade.                                                                                                                                                                      

Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements:
  • Each row contains the title, rating, and all showtimes of a unique movie.
  • A space is placed before and after each vertical separator ('|') in each row.
  • Column 1 displays the movie titles and is left justified with a minimum of 44 characters.
  • If the movie title has more than 44 characters, output the first 44 characters only.
  • Column 2 displays the movie ratings and is right justified with a minimum of 5 characters.
  • Column 3 displays all the showtimes of the same movie, separated by a space.

Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows.

Ex: If the input of the program is:

movies.csv

and the contents of movies.csv are:

16:40,Wonders of the World,G 20:00,Wonders of the World,G 19:00,Journey to Space,PG-13 12:45,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 15:00,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 19:30,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 10:00,Adventure of Lewis and Clark,PG-13 14:30,Adventure of Lewis and Clark,PG-13 19:00,Halloween,R

the output of the program is:

Wonders of the World | G | 16:40 20:00 Journey to Space | PG-13 | 19:00 Buffalo Bill And The Indians or Sitting Bull | PG | 12:45 15:00 19:30 Adventure of Lewis and Clark | PG-13 | 10:00 14:30 Halloween | R | 19:00
Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program
first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following
requirements:
• Each row contains the title, rating, and all showtimes of a unique movie.
• A space is placed before and after each vertical separator ('1') in each row.
• Column 1 displays the movie titles and is left justified with a minimum of 44 characters.
• If the movie title has more than 44 characters, output the first 44 characters only.
• Column 2 displays the movie ratings and is right justified with a minimum of 5 characters.
• Column 3 displays all the showtimes of the same movie, separated by a space.
Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive
rows.
Ex: If the input of the program is:
movies.csv
and the contents of movies.csv are:
16:40, Wonders of the World, G
20:00, Wonders of the World, G
19:00, Journey to Space, PG-13
12:45, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG
15:00, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG
19:30, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG
10:00, Adventure of Lewis and Clark, PG-13
14:30, Adventure of Lewis and Clark, PG-13
19:00, Halloween, R
the output of the program is:
Wonders of the World
|
|
Journey to Space
Buffalo Bill And The Indians or Sitting Bull |
Adventure of Lewis and Clark
Halloween
391908 2626244x37x7
G | 16:40 20:00
PG-13 | 19:00
PG | 12:45 15:00 19:30
| PG-13 | 10:00 14:30
|
R | 19:00
Transcribed Image Text:Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements: • Each row contains the title, rating, and all showtimes of a unique movie. • A space is placed before and after each vertical separator ('1') in each row. • Column 1 displays the movie titles and is left justified with a minimum of 44 characters. • If the movie title has more than 44 characters, output the first 44 characters only. • Column 2 displays the movie ratings and is right justified with a minimum of 5 characters. • Column 3 displays all the showtimes of the same movie, separated by a space. Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows. Ex: If the input of the program is: movies.csv and the contents of movies.csv are: 16:40, Wonders of the World, G 20:00, Wonders of the World, G 19:00, Journey to Space, PG-13 12:45, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG 15:00, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG 19:30, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG 10:00, Adventure of Lewis and Clark, PG-13 14:30, Adventure of Lewis and Clark, PG-13 19:00, Halloween, R the output of the program is: Wonders of the World | | Journey to Space Buffalo Bill And The Indians or Sitting Bull | Adventure of Lewis and Clark Halloween 391908 2626244x37x7 G | 16:40 20:00 PG-13 | 19:00 PG | 12:45 15:00 19:30 | PG-13 | 10:00 14:30 | R | 19:00
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Instructions:

I need Python help.

The problem I am trying to figure out so that when we work a similar problem in class I can do my assignment.  Tonights assignment is a participation thing, Friday I need to do a similar assignment in class for a grade.                                                                                                                                                                      

Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements:
  • Each row contains the title, rating, and all showtimes of a unique movie.
  • A space is placed before and after each vertical separator ('|') in each row.
  • Column 1 displays the movie titles and is left justified with a minimum of 44 characters.
  • If the movie title has more than 44 characters, output the first 44 characters only.
  • Column 2 displays the movie ratings and is right justified with a minimum of 5 characters.
  • Column 3 displays all the showtimes of the same movie, separated by a space.

Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows.

Ex: If the input of the program is:

movies.csv

and the contents of movies.csv are:

16:40,Wonders of the World,G 20:00,Wonders of the World,G 19:00,Journey to Space,PG-13 12:45,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 15:00,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 19:30,Buffalo Bill And The Indians or Sitting Bull's History Lesson,PG 10:00,Adventure of Lewis and Clark,PG-13 14:30,Adventure of Lewis and Clark,PG-13 19:00,Halloween,R

the output of the program is:

Wonders of the World | G | 16:40 20:00 Journey to Space | PG-13 | 19:00 Buffalo Bill And The Indians or Sitting Bull | PG | 12:45 15:00 19:30 Adventure of Lewis and Clark | PG-13 | 10:00 14:30 Halloween | R | 19:00
 
Expert Solution
arrow_forward
Explanation

Here I have taken input from the user and then stored it into a variable.

Next, I opened the CSV file and then copied the content into a dictionary where the key is the combination of the movie title and rating separated by a comma and the value is the list of showtime.

Next, I looped over the dictionary and extracted the values from it.

In the end, I have printed the extracted values in the form of a table as per the question.

arrow_forward
Answer

Python code:

import csv

# user input
filename = input("Enter the CSV file name: ")

movies_dict = {}
with open(filename,'r') as file:    #opening the file
    reader = csv.reader(file)
    for row in reader:              #reading the content
        key = row[1] +','+ row[2]
        tempList=[]
        if key in movies_dict:      #checking and stroing in form of dictionary
            tempList = movies_dict[key]
        tempList.append(row[0])
        movies_dict[key] = tempList
# looping over the dictionary and printinng the data
for key,value in movies_dict.items():
    # extarcting the values
    tempList = key.split(',')
    movieName = tempList[0]
    movieRating = tempList[1]
    # if the movie title is greater than 44 then snipping it
    if len(movieName) > 44:
        movieName = movieName[:44]
    print(movieName.ljust(44),end=" | ")
    print(movieRating.rjust(5),end=" | ")
    for time in value:
        print(time,end=" ")
    print()
FOLLOWUP:
Step 1 ::

- We have to rectify the error we are getting. 

arrow_forward
Step 2 ::

- In line 16, the error we are getting is : 'templist' is not defined.

- The used list to add the values is temp_list and not templist.

- The error is using templist instead of temp_list. 

List name used has the error here.

 

- The corrected code for line 16 :: 

temp_list.append(row[0])  

 

WHICH BRINGS US TO WHERE WE ARE NOW!

I have made the neccessary suggested above. Below I will post the screen shot of my code as well as my output for reference.

The code is mostly functioning thanks to you expert help. on the last line the line:

print(time)

prints everything correctly except it only prints the final time in all the options when some are supposed to have multiple times. I tried the use the original sected print statement of:

print(time, end=' ')

however the output changed to a single line printing everything across but still not actually printing the correct time output either. Which is why I had to use the first option. 

the code sorted all the rest of the fields correctly. As you will see when I post the pictures.

My remaining question is simply how can I adjust the code to include ALL the times in the file oppsed to only the final one. An example of what the file actually shows is above. in the original instructions.

 

1 import csv
2
3 filename = input()
4
5 movies_dict = {}
6 with open(filename, 'r') as file:
7
movie list
csv.reader (file)
8
for row in movie list:
9
10
11
12
13
14
15
16 for key, value in movies_dict.items():
17
18
BARHEEZE
19
20
21
22
23
24
25
26
27
28
29
30
key = row[1] +','+ row[2]
movies=[]
if key in movies_dict:
tempList = movies_dict[key]
movies.append(row [0])
movies_dict [key] movies
31
movies = key.split(',')
movie_name = movies [0]
movie_rating = movies[1]
if len(movie_name) > 44:
movie_name = movie_name[:44]
print(movie_name.ljust(44),end=' |
print(movie_rating.rjust(5), end='
for time in value:
#print (time, end='') output is Wonders of the World I
print (time)
G | 20:00 Journey to Space | PG-13 | 19:00Buffalo
Transcribed Image Text:1 import csv 2 3 filename = input() 4 5 movies_dict = {} 6 with open(filename, 'r') as file: 7 movie list csv.reader (file) 8 for row in movie list: 9 10 11 12 13 14 15 16 for key, value in movies_dict.items(): 17 18 BARHEEZE 19 20 21 22 23 24 25 26 27 28 29 30 key = row[1] +','+ row[2] movies=[] if key in movies_dict: tempList = movies_dict[key] movies.append(row [0]) movies_dict [key] movies 31 movies = key.split(',') movie_name = movies [0] movie_rating = movies[1] if len(movie_name) > 44: movie_name = movie_name[:44] print(movie_name.ljust(44),end=' | print(movie_rating.rjust(5), end=' for time in value: #print (time, end='') output is Wonders of the World I print (time) G | 20:00 Journey to Space | PG-13 | 19:00Buffalo
Your output
Expected output
Wonders of the World
|
Journey to Space
|
Buffalo Bill And The Indians or Sitting Bull |
Adventure of Lewis and Clark
|
Halloween
|
Wonders of the World
|
Journey to Space
|
Buffalo Bill And The Indians or Sitting Bull |
Adventure of Lewis and Clark
|
Halloween
|
G | 20:00
PG-13 | 19:00
PG | 19:30
PG-13 | 14:30
R
19:00
G | 16:40 20:00
PG-13 | 19:00
PG | 12:45 15:00 19:30
PG-13 | 10:00 14:30
R | 19:00
Transcribed Image Text:Your output Expected output Wonders of the World | Journey to Space | Buffalo Bill And The Indians or Sitting Bull | Adventure of Lewis and Clark | Halloween | Wonders of the World | Journey to Space | Buffalo Bill And The Indians or Sitting Bull | Adventure of Lewis and Clark | Halloween | G | 20:00 PG-13 | 19:00 PG | 19:30 PG-13 | 14:30 R 19:00 G | 16:40 20:00 PG-13 | 19:00 PG | 12:45 15:00 19:30 PG-13 | 10:00 14:30 R | 19:00
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

fI think I understand where you are headed, However I get an error. I added my code i typoed in. I proofed it to your code but I am not getting your result. I typed it all out I did not copy and paste as I wanted to type it and understand it as I did. I attached the code and the error code maybe you can find what I am doing wrong. 

= zyBooks
1 import csv
2
3 filename = input('Enter the csv file name: ')
4
5 movies_dict = {}
6
7 with open(filename, 'r') as file:
reader = csv. reader(file)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
My library > ITSE 14/9: Introduction to Scri...
9.13: LAB: Movie show time display
22
23
24
25
26
27
28
29
30
31
32
33
ليا لل
for row in reader:
key = row[1] +','+ row[2]
temp_list = []
if key in movies_dict:
temp_list = movie_dict[key]
templist.append(row[0])
movies_dict [key] = temp_list
for key, value in movies_dict.item():
temp_list = key.split('.')
movie_name = temp_list[0]
movie_rating = temp_list[1]
if len(movie_name) > 44:
movie_name = movie_name[:44]
print (movieName.ljust (44), end=" | ")
print(movieRating.rjust(5),end=" | ")
for time in value:
print (time, end=" ")
print()
Transcribed Image Text:= zyBooks 1 import csv 2 3 filename = input('Enter the csv file name: ') 4 5 movies_dict = {} 6 7 with open(filename, 'r') as file: reader = csv. reader(file) 8 9 10 11 12 13 14 15 16 17 18 19 20 21 My library > ITSE 14/9: Introduction to Scri... 9.13: LAB: Movie show time display 22 23 24 25 26 27 28 29 30 31 32 33 ليا لل for row in reader: key = row[1] +','+ row[2] temp_list = [] if key in movies_dict: temp_list = movie_dict[key] templist.append(row[0]) movies_dict [key] = temp_list for key, value in movies_dict.item(): temp_list = key.split('.') movie_name = temp_list[0] movie_rating = temp_list[1] if len(movie_name) > 44: movie_name = movie_name[:44] print (movieName.ljust (44), end=" | ") print(movieRating.rjust(5),end=" | ") for time in value: print (time, end=" ") print()
Run program
Program errors displayed here
Traceback (most recent call last):
File "main.py", line 16, in <module>
templist.append (row [0])
NameError: name 'templist' is not defined
Program output displayed here
Enter the csv file name:
Coding trail of your work
7/7 R-
Input (from above)
What is this?
min: 22
main.py
(Your program)
Output (shown below)
Transcribed Image Text:Run program Program errors displayed here Traceback (most recent call last): File "main.py", line 16, in <module> templist.append (row [0]) NameError: name 'templist' is not defined Program output displayed here Enter the csv file name: Coding trail of your work 7/7 R- Input (from above) What is this? min: 22 main.py (Your program) Output (shown below)
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education