Question: Using python complete the functions in the provided script, function definitions are provided below: Please avoid using any Python facilities/capabilities we have yet to cover
Using python complete the functions in the provided script, function definitions are provided below:
Please avoid using any Python facilities/capabilities we have yet to cover in the course.
Please use expressive variable names.
# ALL FILES YOUR CODE CREATES NEED TO GO IN THE "MYFILES" FOLDER
# YOU ARE NOT TO ALTER ANY GIVEN FILE IN ANY WAY, OR ADD ANYTHING
# ANY FILE OR FOLDER TO ANY GIVEN FOLDER
# ASSUME THESE FOLDERS AND FILES EXIST FOR SUBMISSION
# NOTE: NONE OF THE SOLUTIONS FOR ASSIGNMENT CAN USE THE CSV MODULE
# NOTE: NONE OF THE SOLUTIONS FOR ASSIGNMENT CAN USE THE PANDAS MODULE
# TESTS ARE NOT PROVIDED THIS WEEK. PAY CLOSE ATTENTION TO
# THE PROMPTS, VISUALLY CHECK FILES YOU CREATE TO MAKE SURE
# THEY ARE IN THE CORRECT OUTPUT FOLDER AND CONTAIN THE TEXT YOU INTENDED TO WRITE.
def prettify_movie_names(file_path: Path) -> bool:
- create a function named above that opens the movie list file within the files folder and writes it back out to myfiles with each line in this format:
MOVIENAME (YEAR)
instead of the current format, which is
MOVIENAME = YEAR
- If everything works out, return True, if there are any problems reading the file, return False
- prettify_movie_names(file_path=Path('files', 'movie.txt') should return True
- prettify_movie_names(file_path=Path('files', 'movie2015.txt') should return False (because it doesn't exist)
Warning, you can't just write the data back to the original file.
You have to use the same file name as the one given, but store your updated version in the myfiles folder.
The output will be like this:
- The Terminator (1984)
- Mad Max 2: The Road Warrior (1981)
- The Invisible Man (1933)
query_movie_list
- This function takes a single parameter. It can either be a movie name (string) or a date (could be a string or int).
- If a movie name is given, you need to return the corresponding year(s) from movies.txt as strings.
- It just so happens that each movie is listed once, so this tuple will either be empty (if the move doesn't exist)
or it will contain a single item.
- If a movie year is given (in int or str format), you need to return all movie(s) from that year in a tuple. If the year is not found, then you need to return an empty tuple.
E.g.:
query_movie_list('Aliens') should return (1986,)
query_movie_list(1981) should return ('Mad Max 2: The Road Warrior', 'The Evil Dead')
you don't need any error handling for this function.
movies.txt
The Terminator = 1984
Mad Max 2: The Road Warrior = 1981
The Invisible Man = 1933
E.T. The Extra-Terrestrial = 1982
Aliens = 1986
The Evil Dead = 1981
Script:
def prettify_movie_names(file_path: Path) -> bool:
print('***REPLACE*** This line with your code')
def query_movie_list(query) -> tuple:
print('***REPLACE*** This line with your code')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
