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
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.
- 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.csvand 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,Rthe 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:00Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
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.
- 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.csvand 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,Rthe 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:00Here 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.
Python code:
- We have to rectify the error we are getting.
- 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.
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.