Question

Python3, write a program, specific information is in the graphs, I got 7 marks out of 10, you may change my codes to let it gives correct output,restrications are also on the graph, for loop, in key word, enumerate,zip,slices, with key word can't be used. All the information is on the graph, is_shakespeare_play(line) may be a function given that can check whether is Shakespeare play

Question 2- 10 marks Write the function keep titles short (filename, max charactars) which takes the string filename and the

Answer question here .titles short(filenane det keep if Type (filename) Yaise TypeEnor(Wrmg ,max_characters) !ニstr type(mar-

Question 2- 10 marks Write the function keep titles short (filename, max charactars) which takes the string filename and the integer max characters. The function should open the file specified by filename, and return True if all the lines in the file contain fewer than or equal to max characters characters (including spaces, punctuation, etc). However, If either of the parameters are of the wrong data type. the function should raise a TypeError with the content of the error being "Wrong data type ! " If the function is unable to open the file for whatever reason, it should raise an 1OError If any line in the file is not the title of a Shakespeare plav. the function should raise a ValueError. You can check whether a line is a Shakespeare play by using the is shakespeare_play (line) function, which will return True if line is the title of a Shakespeare play. It is recommended that you use the readlines () function, and refer to the appendix for a list of other functions and keywords which may be helpful. Examples: File contents Is play Return value/Error Parameters tragedies.txt: Hamlet True tragedies.txt', 20 True King Lear Ro True and Juliet True comedies.txt: The Tempest True False 'comedies.txt', 15 All's Well That End's Well True problem plays.txt: The Winter's Tale True True problem plays.txt', 19 True Measure for Measure TypeError "Wrong data type! " 5, 2 (Non-existent file) IOError gone.txt', 5 quotes.txt: To be or not to be False ValueError 'quotes.txt', 6 True Othello False Once more unto the breach Restrictions function print (), len(), int (), float (), type ( ) , Only Allowed: while loops, if statements. list method append (), string method format(), any file functions or methods from isinstance () the reference page. keywords elif, else, return, break, continue, def, self, None, try, raise, except, finally, is, import sys. Any Operators from the reference page. Any exception throwing and catching Remember: Do not use a for loop, do not use the in keyword, do not use enumerate/zip, do not use slices e.g. [1:), do not use lambda functions e.g. with sorted), do not use the with keyword. Marks will be deducted.
Answer question here .titles short(filenane det keep if Type (filename) Yaise TypeEnor("Wrmg ,max_characters) !ニstr type(mar-choractag) Int 2 data f=open (tilename, 'y except IDError Yaise 1DErOY fines = f-readlines() det isghakespeare-pytime) f.clex wRilelen(lines) Slines D 11 2 13 itin shotespeat-pla, (line) Yeturn True rail 4 kt- return Fase 16 17 Line= limes Q=!81 1 while
0 0
Add a comment Improve this question Transcribed image text
Answer #1


def keep_titles_short(filename , max_characters): if type(filename) ! raise TypeError ( Wrong Data Type!) try: file type (m

Add a comment
Know the answer?
Add Answer to:
Python3, write a program, specific information is in the graphs, I got 7 marks out of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python3 please use while loop to solve this question,specific information is on the graph Question 2...

    Python3 please use while loop to solve this question,specific information is on the graph Question 2 - 15 marks Write the function read_file_center50 (filename). The function returns a list of 50 strings that are at the center of the file. A file has n lines, then is the center. A list of length 50 is returned, where the first line is 25 and the last line is 2 + 25. If the file has n < 50 lines, then only...

  • I am having a little trouble with my Python3 code today, I am not sure what...

    I am having a little trouble with my Python3 code today, I am not sure what I am doing wrong. Here are the instructions: and here is my code: update: I have seen I did not close x in sumFile and I am still only getting a 2/10 on the grader. any help appreciated. Lab-8 For today's lab you going to write six functions. Each function will perform reading and/or write to a file Note: In zybooks much like on...

  • Write a complete C program that inputs a paragraph of text and prints out each unique...

    Write a complete C program that inputs a paragraph of text and prints out each unique letter found in the text along with the number of times it occurred. A sample run of the program is given below. You should input your text from a data file specified on the command line. Your output should be formatted and presented exactly like the sample run (i.e. alphabetized with the exact spacings and output labels). The name of your data file along...

  • C Language program. Please follow the instructions given. Must use functions, pointers, and File I/O. Thank...

    C Language program. Please follow the instructions given. Must use functions, pointers, and File I/O. Thank you. Use the given function to create the program shown in the sample run. Your program should find the name of the file that is always given after the word filename (see the command line in the sample run), open the file and print to screen the contents. The type of info held in the file is noted by the word after the filename:...

  • Python3 : question about object-oriented programming, Please write program in the template(critter.py),specific information is on the graphs the missing words in the 4th line are 'To save an attri...

    Python3 : question about object-oriented programming, Please write program in the template(critter.py),specific information is on the graphs the missing words in the 4th line are 'To save an attribute, attach it to this self keyword' W11 - Critters Implement the Critter class. Each critter C has attributes species, size, and age The constructor accepts arguments for the attributes above, in the order above. You can expect size and age to be numeric values Each critter C has a can_eat) method,...

  • Write a program to read the contents of data.txt file, and determine the smallest value (min),...

    Write a program to read the contents of data.txt file, and determine the smallest value (min), largest value (max), and the average value (ave). The minimum, maximum, and average values must be calculated in the function calc(). Remember to declare the stdlib.h library, so that you can use the atof function, which will convert the number in the text file into float number. Also, remember to check if there is an error opening the file or not. If there is...

  • Problem 1 Recall that when the built-in function open() is called to open a file for...

    Problem 1 Recall that when the built-in function open() is called to open a file for reading, but it doesn't exist, an exception is raised. However, if the file exists, a reference to the opened file object is returned. Write a function safeOpen() that takes one parameter, filename - a string giving the pathname of the file to be opened for reading. When safeOpen() is used to open a file, a reference to the opened file object should be returned...

  • The program is written in c. How to implement the following code without using printf basically...

    The program is written in c. How to implement the following code without using printf basically without stdio library? You are NOT allowed to use any functions available in <stdio.h> . This means you cannot use printf() to produce output. (For example: to print output in the terminal, you will need to write to standard output directly, using appropriate file system calls.) 1. Opens a file named logfle.txt in the current working directory. 2. Outputs (to standard output usually the...

  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT