Home / Expert Answers / Computer Science / description-of-program-you-are-to-write-a-python-program-which-requires-1-command-line-argument-tha-pa510

(Solved): Description of program You are to write a Python program which requires 1 command-line argument. Tha ...



Description of program
You are to write a Python program which requires 1 command-line argument. That command-line argument will be the filename of a text file. The text file will contain information about TV shows. Your program will read in the contents of the file, then print out information about the TV shows in a nice tabular format.
If the user does not supply a command-line argument, or supplies too many, then you should print an error message and quit right away, using sys.exit(1)
Example usage
Attached to this assignment description is a sample input file, tv-shows.txt . If you run your program with tv-shows.txt as the input, you should get the following output:
Could not be parsed: this is not valid.e

Could not be parsed: this is also not valid, 1.1

jetsons
=======
Average rating: 3.405
Season Episode Rating
01 01 4.00
01 02 4.00
01 03 4.00
01 04 4.00
01 05 4.00
01 06 4.00
01 07 4.00
01 08 4.00
01 09 4.00
01 10 4.00
01 11 4.00
01 12 4.00
01 13 4.00
02 03 2.50
02 04 2.50
02 05 2.50
02 06 2.50
02 07 2.50
02 08 2.50
02 09 2.50
02 14 2.00


building houses
===============
Average rating: 1.547
Season Episode Rating
01 02 1.50
01 03 1.70
01 04 1.44


big thing
=========
Average rating: 3.050
Season Episode Rating
01 04 3.00
01 06 3.10


squid game
==========
Average rating: 3.433
Season Episode Rating
01 02 3.00
01 01 4.00
01 03 3.30


ax murdering
============
Average rating: 2.500
Season Episode Rating
01 01 2.50

Some notes about this:
The ordering of the TV shows does not matter. You can print them out in any order
The ordering of the episodes and seasons within a TV show do not matter. You can print them out in any order
If the input is invalid for a particular line, print a message saying so (above the tabular output)
Input
The input is line-based text. Each line of text contains (from left-to-right) the TV show title (string), the season number (int), the episode number (int), and the rating (float). Extra notes:
All titles should be treated in a case-insensitive manner. I suggest converting everything to lowercase using the .lower() method call
If a title begins with the word "a" or "the", you must ignore that word. E.g., "The Jetsons" must be treated as simply "jetsons"
The title may not contain . (period) or - (hyphen) characters
The title is separated from the rest of the line by a . (period) or - (hyphen) character, sometimes with spaces. The title should not end in a space, but may have a space in the middle.
The season begins with the letter "s"
The season is optional. If the season is missing, it should be assumed to be 1
The episode number immediately follows the season, if the season exists. It begins with the letter "e"
The episode sometimes may be a RANGE between 2 numbers. E.g., e03 is just episode 3, but e03-e06 is episodes 3 4 5 6. You may assume that the 2nd number is always bigger than the 1st number. For an episode range, you must add all the episodes
After the episode comes a comma, sometimes with spaces around it
At the end of the line comes a rating (a score of 1 to 5, indicating how good the episode is)
Output
You must group together episodes of the same TV show. Remember that they should be grouped together in a case-insensitive way ("Jetsons" and "jetsons" are the same) and ignoring any "a" or "the" at the beginning ("The Jetsons" and "jetsons" are the same).
For each TV show:
Print the name of the TV show in all lowercase
Print a line of '=' symbols which is same length as the TV show title
Calculate and print the average rating with 3 digits after the decimal point. The average rating must consider all episodes equally (even if those episodes are part of a range)
Then, print "Season", "Episode" and "Rating" column headings, each with a width of 10
Then, for each episode that is part of this TV show, print the season number (2 digits, with a leading 0 if necessary), episode number (2 digits, with a leading 0 if necessary), and rating (2 digits after the decimal)
Then, print 2 blank lines
Functional requirements
Unlike with previous assignments, I don't have any strict functional requirements. It is up to you to decide where (or if) to use lists, where to use functions, etc. Part of your mark will come from avoiding redundant or confusing code. If you would like hints, please post on the discussions board. If you would like more sample input (and corresponding output), please let me know.

This is input file 

jetsons.s01e01-13   , 4
building Houses.s01e02, 1.5
The Jetsons - S02e03-09  ,2.5
A Big thing - s01e04,3
Squid game - e2, 3
The big thing.s01e06, 3.1
Building houses.s01e03, 1.7
this is not valid.e
Building Houses.s01e04  ,   1.44
Squid Game -e1, 4
the squid game.s01e03, 3.3
this is also not valid, 1.1
jetsons.s02e14, 2
Ax Murdering.s01e01,2.5



We have an Answer from Expert

View Expert Answer

Expert Answer


# Open a file for writing and insert some records >>> f = open('test.txt', 'w') //always we have to firstly open it >>> f.write('apple\n') >>> f.write('orange\n') >>> f.write('pear\n') // use for writing into the file >>> f.close() # Always cl
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe