0% found this document useful (0 votes)
6 views3 pages

Python Exception and Module Based Questions

The document contains a comprehensive set of questions related to exception handling and the random module in Python, covering definitions, differences between error types, and the purpose of various blocks in exception handling. It also includes practical programming tasks to demonstrate exception handling and random number generation. Additionally, it addresses time-related functions and their applications in Python programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Python Exception and Module Based Questions

The document contains a comprehensive set of questions related to exception handling and the random module in Python, covering definitions, differences between error types, and the purpose of various blocks in exception handling. It also includes practical programming tasks to demonstrate exception handling and random number generation. Additionally, it addresses time-related functions and their applications in Python programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Exception Handling and Modules based Questions

What is an exception in Python?

Differentiate between syntax error and exception.

Why is exception handling required?

What happens when an exception is not handled?

What is the purpose of try block?

What is the role of except block?

Can a try block exist without except? Explain.

What is the use of else block in exception handling?

What is the purpose of finally block?

Can finally execute even if exception occurs?

What is ZeroDivisionError?

What is ValueError?

What is TypeError?

What is IndexError?

What is KeyError?

What is PermissionError?

What is AssertionError?

When does FileNotFoundError occur?

Why do we use multiple except blocks?

What is the order of exception handling?

What is a generic Exception block?

Why should Exception be placed at the end?

How do you raise an exception manually?

What is the use of raise keyword?

Can we create user-defined exceptions? Explain.

Write a Python program to handle division by zero.

Write a program to demonstrate try-except-else-finally.

Write a program to validate input using assertion.

Write a program to handle file-related exceptions.

Write a program to catch multiple exceptions in a single try block.

What is the random module in Python?


Why do we use the random module?

What does import random do?

What is pseudo-random number generation?

Is random number generation truly random? Explain.

What is the random module in Python?

Why do we use the random module?

What does import random do?

What is pseudo-random number generation?

Is random number generation truly random? Explain.

What does random() function return?

Difference between randint() and randrange()?

What is the use of choice() function?

What does shuffle() do?

What is the purpose of seed() function?

What does uniform() generate?

What is the purpose of rng = [Link]()?

Difference between random() and Random() class?

Why use separate random generator objects?

What is the purpose of rng = [Link]()?

Difference between random() and Random() class?

Why use separate random generator objects?

Write a Python program to generate random numbers between 1 and 100.

Write a program to simulate rolling a dice using random module.

Write a program to generate random password.

Write a program to shuffle a list of numbers.

Write a program to generate N unique random numbers.

What is the use of sleep() function?

Difference between time() and ctime()?

What does localtime() return?

What is the purpose of strftime()?

What does perf_counter() measure?

Write a program to display current system time.


Write a program to delay execution by 5 seconds.

Write a program to calculate execution time of a program.

Write a program to create a simple digital clock.

Write a program to display current date and time in formatted style.

Write a program using random and time to simulate a lottery system.

Write a program using random and exception handling for a guessing game.

Write a program to retry an operation after a delay using [Link]() and exception handling.

Write a program to generate timestamped log messages.

You might also like