Source Code of Problem A:
import csv
with open('Tourist.csv', 'w', newline='') as f:
writer = csv.writer(f)
lst = [['T01', 'Sam', 'New York'], ['T02', 'Peter', 'London'], ['T03', 'Kartik', 'Inida'], ['T04', 'Scott', 'Rusia']]
writer.writerows(lst)
def SNAMES():
with open('Tourist.csv', 'r') as fl:
read = csv.reader(fl)
countS = 0
for line in read:
if line[1][0] == 'S':
countS += 1
print(line)
print(f'No. of Name begin with S {countS}')
SNAMES()
OutPut ScreenShot :
Source-Code of Problem B:
import mysql.connector
db = mysql.connector.connect(host='localhost', user='root', passwd='mysql')
cursor = db.cursor()
try:
cursor.execute('CREATE DATABASE HOBBY')
except Exception:
pass
cursor.execute('USE HOBBY')
cursor.execute('DROP TABLE IF EXISTS hobbyclub')
cursor.execute('CREATE TABLE hobbyclub (id int, member varchar(30), hobby varchar(30))')
cursor.execute("INSERT INTO hobbyclub VALUES(328, 'Akash', 'Cricket')")
cursor.execute('SELECT * FROM hobbyclub')
data = cursor.fetchall()
print("Displaying the data of Relation Hobby")
for row in data:
print(row)
db.commit()
db.close()
Output Screenshot :