Python Practice Exam 2023 with 100% correct answers
An exception handler is a piece of code that is written using the try/except statement: T/F True If a file with the specified name already exists when the file is opened and the file is opened in 'w' mode, then an alert will appear on the screen: T/F False If the last line in a file is not terminated with n, the readline method will return the line without n: T/F True When a piece of data is read from a file, it is copied from the file into the program: T/F False Which mode specifier will erase the contents of a file if it already exists and create the file if it does not already exist?: - 'r' - 'e' - 'w' - 'a' 'w' Which of the following is associated with a specific file and provides a way for the program to work with that file?: - the filename - the file object - the file variable - the file extension the file object What will be the output after the following code is executed and the user enters 75 and 0 at the first two prompts? def main(): try: total = int(input('enter total cost of i num_items = int(input('number of items" average = total/ num_items except ZeroDivisionError: print('Error: cannot have 0 items') except ValueError: print(error: number of items cannot be main() Error: cannot have 0 items
Document information
- Uploaded on
- July 28, 2023
- Number of pages
- 6
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers