Task 1: Reading a File and Handling Errors
Problem:
Problem Statement: Write a Python program that:
- Creates a dictionary where student names are keys and their marks are values.
- Asks the user to input a student's name.
- Retrieves and displays the corresponding marks.
- If the student’s name is not found, display an appropriate message.
Expected Output
If the file exists: Enter the student's name:Lata Lata marks: 98
If the file does not exist: Enter the student's name:55 Student not found.
Task 2: Demonstrate List Slicing
Problem:
Problem Statement: Write a Python program that:
- Creates a list of numbers from 1 to 10.
- Extracts the first five elements from the list.
- Reverses these extracted elements.
- Prints both the extracted list and the reversed list
Expected Output Original list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Extracted first five elements: [1, 2, 3, 4, 5] Reversed extracted elements: [5, 4, 3, 2, 1]
How to Run the Programs
Make sure you have Python installed.
Save the code for each task in a file (e.g., Assignment5.py).
Open a terminal or command prompt in the same directory.
Run the programs using the following commands:
python Assignment5.py