BCA4thSemPythonLabManualPartB
BCA4thSemPythonLabManualPartB
import re
print("String source:")
print(source,"\n")
pattern="cherry"
import re
#verify email
'''email_pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
if re.match(email_pattern, email):
print("Valid email id")
else:
print("Invalid email id")'''
# Verify password
password_pattern = r'^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)[A-Za-z\d]{8,}$'
if re.match(password_pattern, password):
print("Valid password id")
else:
print("Invalid password id")
# slicing
print(fruit[0:2])
#traversing
for key,value in person.items():
print(key,value)
import sqlite3
# Create a table
cursor.execute('''
CREATE TABLE IF NOT EXISTS employees (
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER,
salary REAL
)
''')
def showRecords():
# Retrieve data from the table
cursor.execute("SELECT * FROM employees")
rows = cursor.fetchall()
showRecords()
import tkinter as tk
try:
#conde that may raise an exception
num1=int(input("Enter the first number : "))
num2=int(input("Enter the second number : "))
result=num1/ num2
print("Result: ", result)
print("Result" +result)
except ValueError:
print("Error: Invalid input. Please enter a valid number.")
except ZeroDivisionError:
print("Error: cannot divide by zero. ")
except Exception as e:
print("An erro occured: ", str(e))
finally:
print("Finally block : Error occures or not, i will be executed")
while True:
print("1. Draw Line Chart")
print("2. Draw Bar Chart")
print("3. Exit")
choice=input("Enter the choice : ")
plt.xlabel('YEAR')
plt.ylabel('COUNT')
plt.title('SDC BCA STRENGTH')
plt.show()
plt.show()
elif(choice=="3"):
print("Exiting......")
break
else:
print("invalid choice")
while True:
print("1. Draw Histogram Chart")
print("2. Draw Pie Chart")
print("3. Exit")
choice=input("Enter the choice : ")
# Add a title
plt.title('XYZ College')
elif(choice=="3"):
print("Exiting......")
break
else:
print("invalid choice")
# B11. Create DataFrame From Excel Sheet using pandas and perform operation on data Frames
# Add a new column 'Age+10' with age incremented by 10 for each person
df['Age+10'] = df['Age'] + 10
print("DataFrame with new 'Age+10' column:")
print(df)