PDS Files Quiz

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the output of the following code? number = 5.0 try: r = 10/number print(r) except: print("Oops! Error occurred.") 1) Oops! Error occurred. 2) 2.0 3) 2.0 Oops! Error occurred. 4) None object

2.0

For the following code, Which of the following statement is true? f = open('test.txt', 'r', encoding = 'utf-8') f.read() 1) This program reads the content of test.txt file. 2) If test.txt contains newline, read() will return newline as '\n'. 3) You can pass an integer to the read() method. 4) All of the above.

All of the above.

Which of the following is correct? 1) An exception is an error that occurs at the runtime. 2) A syntax error is also an exception. 3) An exception is used to exclude a block of code in Python. 4) All of the above.

An exception is an error that occurs at the runtime.

What will happen if you try to open a file that doesn't exist? 1) A new file is created 2) Nothing will happen. 3) An exception is raised. 4) None of the above.

An exception is raised.

Which of the following codes closes file automatically if exception occurs? with open("test.txt", encoding = 'utf-8') as f: # perform file operation try: f = open("test.txt",encoding = 'utf-8') # perform file operations finally: f.close() 1) None of the above 2) Both of the above

Both of the above

What does the following code do? f = open("test.txt") 1) Opens test.txt file for both reading and writing 2) Opens test.txt file for reading only 3) Opens test.txt file for writing only 4) Opens test.txt file in god mode

Opens test.txt file for reading only

What does the following code do? try: # code that can raise error pass except (TypeError, ZeroDivisionError): print("Two") 1) Prints Two if exception occurs (doesn't matter which exception). 2) Prints Two if exception doesn't occur. 3) Prints Two if TypeError or ZeroDivisionError exception occurs. 4) Prints Two only if both TypeError and ZeroDivisionError exception occurs.

Prints Two if TypeError or ZeroDivisionError exception occurs.

What does the following code do? os.listdir() 1) Prints the current working directory. 2) Prints all directories (not files) inside the given directory. 3) Prints all directories and files inside the given directory. 4) Makes a new directory.

Prints all directories and files inside the given directory.

Which of the following statement is true? 1) You cannot create custom exceptions in Python. 2) You can create a user-defined exception by deriving a class from Exception class. 3) You can create a user-defined exception by deriving a class from Error class. 4) None of the above.

You can create a user-defined exception by deriving a class from Exception class.

Opening a file in 'a' mode 1) opens a file for reading 2) opens a file for writing 3) opens a file for appending at the end of the file 4) opens a file for exclusive creation

opens a file for appending at the end of the file


Kaugnay na mga set ng pag-aaral

Computer Science II - Midterm Practice

View Set

Immune sys---Lupus, arthr/connect IGGY 20, Chapter 18 Iggy Practice Questions, Chapter 46 10th edition, Brunner Chapter 39, Musculoskeletal Trauma

View Set

domain quiz - lifespace development

View Set

Chapter 4: Understanding Food and Nutrition Labels

View Set

Unit 8: Global Atmospheric Change

View Set

الوحدة الأولى: المقدمة والمخالفات المرورية والنقاط المرورية

View Set

castillo mid term multiple choice and fill in the blanks

View Set

EXAM 2 Chapter 51: Assessment and Management of Patients with Diabetes Prep-U, EXAM 2 Adult Prep U CH 51 Assessment and Management of Patients With Diabetes part 2

View Set