Python Programming Practice - Code for 4 Questions
1. Write a program to read the contents of a file and display it.
# File Reading Example
file = open("[Link]", "r")
content = [Link]()
print("File content:\n", content)
[Link]()
2. Write a program to copy files using shutil module.
import shutil
# Copying a file
[Link]("[Link]", "copy_sample.txt")
print("File copied successfully!")
3. Write a program to demonstrate assertion.
# Assertion Example
marks = 75
assert marks >= 0 and marks <= 100, "Marks should be between 0 and 100"
print("Valid marks:", marks)
4. Write a program to log messages of different severity levels.
import logging
# Configure logging
[Link](level=[Link])
[Link]("Debugging in progress")
[Link]("Informational message")
[Link]("This is a warning")
[Link]("An error has occurred")
[Link]("Critical issue!")