Part-B
1. Demonstrate usage of basic regular expression
Output:
Words starting with 'q': ['quick']
Words ending with 'y': ['lazy', 'sunny', 'day']
2. Demonstrate use of advanced regular expressions for data validation.
Output:
Email '[email protected]' is valid: True
Phone number '+15551234567' is valid: True
Password 'Password123!' is valid: True
3. Demonstrate use of List
Output:
Original List: [10, 20, 30, 40, 50]
Element at index 0: 10
Element at index 3: 40
Modified List: [10, 25, 30, 40, 50]
List after appending: [10, 25, 30, 40, 50, 60]
List after inserting: [10, 25, 28, 30, 40, 50, 60]
List after removing: [10, 25, 28, 30, 50, 60]
List after popping: [10, 25, 28, 50, 60]
Popped element: 30
Length of the list: 5
Slice from index 1 to 4: [25, 28, 50]
Is 30 in the list? False
Is 40 in the list? False
Iterating through the list:
10
25
28
50
60
List after clearing: []
4. Demonstrate use of Dictionaries
Output:
Name: Alice
Age: 30
City: New York
Modified dictionary:
{'name': 'Alice', 'age': 31, 'city': 'San Francisco'}
Dictionary after adding occupation:
{'name': 'Alice', 'age': 31, 'city': 'San Francisco', 'occupation': 'Engineer'}
Dictionary after deleting city:
{'name': 'Alice', 'age': 31, 'occupation': 'Engineer'}
Is 'name' a key? True
Is 'city' a key? False
Keys:
name
age
occupation
Values:
Alice
31
Engineer
Key-value pairs:
name: Alice
age: 31
occupation: Engineer
Length of dictionary: 3
Dictionary after clearing: {}
6. Create a GUI using Tkinter module
Output:
7. Demonstrate Exceptions in Python
Output:
5.0
This is finally block.
Output:
Error: Denominator cannot be 0.
This is finally block.