0% found this document useful (0 votes)
22 views6 pages

Baba Black Sheep

Uploaded by

Soham Mukherjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

Baba Black Sheep

Uploaded by

Soham Mukherjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

8/20/25, 10:22 PM all_questions_notebook.

ipynb - Colab

def question_1():
def reverse_string(s): return s[::-1]
def replace_s_with_hash(s): return s.replace('s', '#').replace('S', '#')
def find_repeating_chars(s):
from collections import Counter
return [char for char, count in Counter(s).items() if count > 1]
def encode_string(s): return ''.join([chr(ord(c) + 2) for c in s])
s = input("Enter a string: ")
print("Reversed:", reverse_string(s))
print("Replaced 's' or 'S' with '#':", replace_s_with_hash(s))
print("Repeating characters:", find_repeating_chars(s))
print("Encoded string:", encode_string(s))

format_size format_bold format_italic code link image format_quote format_list_numbered format_list_bulleted horizontal_rule ψ mood

title lorem ipsum dolor sit amet

def question_2():
book_dict = {}
n = int(input("Enter number of books: "))
for _ in range(n):
book = input("Enter book name: ")
author = input("Enter author name: ")
book_dict[book] = author
print("Book Dictionary:", book_dict)

def question_3():
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print("Add:", a + b)
print("Subtract:", a - b)
print("Multiply:", a * b)
print("Divide:", a / b if b != 0 else "Division by zero")

def question_4():
def is_prime(n):
if n < 2: return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0: return False
return True
N = int(input("Enter N: "))
print("Prime numbers:", [x for x in range(2, N + 1) if is_prime(x)])

def question_5():
scores = list(map(int, input("Enter scores: ").split()))
print("Sum of scores ending with 5:", sum(x for x in scores if x % 10 == 5))

def question_6():
##-- Option 1: Display the lowest and the highest classes
##SELECT MIN(Class) AS Lowest_Class, MAX(Class) AS Highest_Class FROM STUDENTS;
##
##-- Option 2: Display the number of students in each class
##SELECT Class, COUNT(*) AS Student_Count FROM STUDENTS GROUP BY Class;
##
##-- Option 3: Display the number of students in class 10
##SELECT COUNT(*) AS Class10_Student_Count FROM STUDENTS WHERE Class = 10;
##
##-- Option 4: Display details of the students of Cricket team
##SELECT S.*
##FROM STUDENTS S
##JOIN SPORTS P ON S.AdmNo = P.AdmNo
##WHERE P.Game = 'Cricket';
##
##-- Option 5: Display AdmNo, Name, Class, Sec, RNo of students with Grade 'A'
##SELECT S.AdmNo, S.Name, S.Class, S.Sec, S.RNo
##FROM STUDENTS S
##JOIN SPORTS P ON S.AdmNo = P.AdmNo
##WHERE P.Grade = 'A';
##
##-- Option 6: Display Name and Phone numbers of class 12 students who play some game
##SELECT DISTINCT S.Name, S.Phone
##FROM STUDENTS S
##JOIN SPORTS P ON S.AdmNo = P.AdmNo
##WHERE S Class = 12;
https://colab.research.google.com/drive/1HZ97GLBElmMrF_iz28rZuZ8gn6zsQ3f7?authuser=2#scrollTo=wQAd3K-zZSWS&printMode=true 1/6
8/20/25, 10:22 PM all_questions_notebook.ipynb - Colab
##WHERE S.Class = 12;
##
##-- Option 7: Display the number of students with each coach
##SELECT Coach_Name, COUNT(DISTINCT AdmNo) AS Student_Count
##FROM SPORTS
##GROUP BY Coach_Name;
##
##-- Option 8: Display Names and Phone numbers of students with Grade 'A' and Coach 'Narendra'
##SELECT S.Name, S.Phone
##FROM STUDENTS S
##JOIN SPORTS P ON S.AdmNo = P.AdmNo
##WHERE P.Grade = 'A' AND P.Coach_Name = 'Narendra';

File "/tmp/ipython-input-1441270316.py", line 38


##WHERE P.Grade = 'A' AND P.Coach_Name = 'Narendra';
^
SyntaxError: incomplete input

Next steps: Explain error

def question_7():
## a) Lowest and highest classes
##SELECT MIN(Class) AS Lowest_Class, MAX(Class) AS Highest_Class FROM STUDENTS;
##
##-- b) Number of students in each class
##SELECT Class, COUNT(*) AS Student_Count FROM STUDENTS GROUP BY Class;
##
##-- c) Number of students in class 10
##SELECT COUNT(*) AS Class10_Student_Count FROM STUDENTS WHERE Class = 10;
##
##-- d) Details of students in the Cricket team
##SELECT S.* FROM STUDENTS S JOIN SPORTS P ON S.AdmNo = P.AdmNo WHERE P.Game = 'Cricket';
##
##-- e) Students with Grade 'A' in Sports
##SELECT S.AdmNo, S.Name, S.Class, S.Sec, S.RNo
##FROM STUDENTS S JOIN SPORTS P ON S.AdmNo = P.AdmNo
##WHERE P.Grade = 'A';
##
##-- f) Name and phone numbers of Class 12 students who play some game
##SELECT DISTINCT S.Name, S.Phone
##FROM STUDENTS S JOIN SPORTS P ON S.AdmNo = P.AdmNo
##WHERE S.Class = 12;
##
##-- g) Number of students with each coach
##SELECT Coach_Name, COUNT(DISTINCT AdmNo) AS Student_Count
##FROM SPORTS GROUP BY Coach_Name;
##
##-- h) Names and phone numbers of students with grade 'A' and coach 'Narendra'
##SELECT S.Name, S.Phone
##FROM STUDENTS S JOIN SPORTS P ON S.AdmNo = P.AdmNo
##WHERE P.Grade = 'A' AND P.Coach_Name = 'Narendra';

def question_8():
con = mysql.connector.connect(host='localhost', user='root', passwd='root')
cur = con.cursor()
cur.execute("SHOW TABLES")
for table in cur:
print(table)
con.close()

def question_9():
con = mysql.connector.connect(host='localhost', user='root', passwd='yourpassword')
cur = con.cursor()
cur.execute("SHOW DATABASES")
for db in cur:
print(db)
con.close()

def question_10():
con = mysql.connector.connect(host='localhost', user='root', passwd='root', database='main')
cur = con.cursor()
n = int(input("How many employees? "))
for _ in range(n):
eid = int(input("ID: "))
name = input("Name: ")
salary = float(input("Salary: "))
cur.execute("INSERT INTO Employee VALUES (%s, %s, %s)", (eid, name, salary))
con.commit()
cur.execute("SELECT * FROM Employee")

https://colab.research.google.com/drive/1HZ97GLBElmMrF_iz28rZuZ8gn6zsQ3f7?authuser=2#scrollTo=wQAd3K-zZSWS&printMode=true 2/6
8/20/25, 10:22 PM all_questions_notebook.ipynb - Colab
for row in cur:
print(row)
con.close()

def question_11():
def menu():
print("1.Add 2.Modify 3.Delete 4.Display 5.Exit")
return int(input("Choice: "))
con = mysql.connector.connect(host='localhost', user='root', passwd='root', database='main')
cur = con.cursor()
while True:
ch = menu()
if ch == 1:
data = (int(input("AccNo: ")), input("Name: "), float(input("Balance: ")), input("Mob: "), input("Email: "))
cur.execute("INSERT INTO Customer VALUES (%s,%s,%s,%s,%s)", data)
con.commit()
elif ch == 2:
acc = int(input("AccNo to modify: "))
bal = float(input("New Balance: "))
cur.execute("UPDATE Customer SET balance=%s WHERE accno=%s", (bal, acc))
con.commit()
elif ch == 3:
acc = int(input("AccNo to delete: "))
cur.execute("DELETE FROM Customer WHERE accno=%s", (acc,))
con.commit()
elif ch == 4:
cur.execute("SELECT * FROM Customer")
for row in cur: print(row)
else:
break
con.close()

def question_12():
with open("first.txt") as f, open("second.txt", "w") as w:
for word in f.read().split():
if word[0].lower() in 'aeiou':
w.write(word + " ")
print("File second.txt written.")

def question_13():
def add():
with open("students.txt", "a") as f:
f.write(input("Roll, Name, Marks: ") + "\n")
def disp():
with open("students.txt") as f:
print(f.read())
while True:
c = input("1.Add 2.Display 3.Exit: ")
if c == '1': add()
elif c == '2': disp()
else: break

def question_14():
def store():
with open("Phonebook.txt", "a") as f:
f.write(input("Name,Phone,Email: ") + "\n")
def search():
name = input("Search Name: ")
with open("Phonebook.txt") as f:
for line in f:
if line.startswith(name): print(line)
def display():
with open("Phonebook.txt") as f: print(f.read())
def update():
name = input("Name to update: ")
new_lines = []
with open("Phonebook.txt") as f:
for line in f:
if line.startswith(name):
new_lines.append(input("New record: ") + "\n")
else:
new_lines.append(line)
with open("Phonebook.txt", "w") as f:
f.writelines(new_lines)
while True:
ch = input("1.Store 2.Search 3.Display 4.Update 5.Exit: ")
if ch == '1': store()
elif ch == '2': search()
elif ch == '3': display()

https://colab.research.google.com/drive/1HZ97GLBElmMrF_iz28rZuZ8gn6zsQ3f7?authuser=2#scrollTo=wQAd3K-zZSWS&printMode=true 3/6
8/20/25, 10:22 PM all_questions_notebook.ipynb - Colab
elif ch == '4': update()
else: break

def question_15():
def createFile():
with open("Book.dat", "ab") as f:
pickle.dump([input("BookNo: "), input("Name: "), input("Author: "), float(input("Price: "))], f)
def countRec(author):
count = 0
with open("Book.dat", "rb") as f:
while True:
try:
rec = pickle.load(f)
if rec[2] == author:
count += 1
except:
break
print("Books by", author, ":", count)
createFile()
countRec(input("Enter author to count: "))

def question_16():
def player_details():
with open("players.dat", "ab") as f:
pickle.dump({'Pcode': input("Code: "), 'Pname': input("Name: "), 'Score': int(input("Score: ")), 'Rank': int(input("Rank: ")
def Display():
with open("players.dat", "rb") as f:
while True:
try: print(pickle.load(f))
except: break
def Player_search():
code = input("Enter Pcode: ")
with open("players.dat", "rb") as f:
while True:
try:
p = pickle.load(f)
if p['Pcode'] == code:
print(p)
except: break
def player_update():
players = []
with open("players.dat", "rb") as f:
while True:
try: players.append(pickle.load(f))
except: break
code = input("Enter Pcode to update: ")
for p in players:
if p['Pcode'] == code:
p['Score'] = int(input("New Score: "))
with open("players.dat", "wb") as f:
for p in players: pickle.dump(p, f)
def delete():
code = input("Enter Pcode to delete: ")
players = []
with open("players.dat", "rb") as f:
while True:
try:
p = pickle.load(f)
if p['Pcode'] != code:
players.append(p)
except: break
with open("players.dat", "wb") as f:
for p in players: pickle.dump(p, f)

def question_17():
def addrecord():
with open("Students.csv", "a", newline='') as f:
w = csv.writer(f)
w.writerow(input("Roll,Name,Marks: ").split(','))
def modifyrecord():
roll = input("Roll to modify: ")
rows = []
with open("Students.csv") as f:
for r in csv.reader(f):
if r[0] == roll:
r[2] = input("New Marks: ")
rows.append(r)
with open("Students.csv", "w", newline='') as f:
csv.writer(f).writerows(rows)
def deleterecord():

https://colab.research.google.com/drive/1HZ97GLBElmMrF_iz28rZuZ8gn6zsQ3f7?authuser=2#scrollTo=wQAd3K-zZSWS&printMode=true 4/6
8/20/25, 10:22 PM all_questions_notebook.ipynb - Colab
roll = input("Roll to delete: ")
rows = [r for r in csv.reader(open("Students.csv")) if r[0] != roll]
with open("Students.csv", "w", newline='') as f:
csv.writer(f).writerows(rows)
def search():
roll = input("Roll to search: ")
for r in csv.reader(open("Students.csv")):
if r[0] == roll: print(r)
def viewall():
for r in csv.reader(open("Students.csv")): print(r)

def question_18():
stack = []
def push():
stack.append((input("Code: "), input("Title: "), float(input("Price: "))))
def pop():
if stack: print("Popped:", stack.pop())
def traverse():
print("Stack:", stack)

def question_19():
stack = []
def add(): stack.append([input("Hostel No: "), input("Total Students: "), input("Total Rooms: ")])
def delete():
if stack: print("Deleted:", stack.pop())
def display(): print("Stack:", stack)

def question_20():
arr = list(map(int, input("Enter numbers: ").split()))
stk = [x for x in arr if x % 5 == 0]
print("Stack:" if stk else "No elements divisible by 5", stk)

def question_21():
stk = list(map(int, input("Stack values: ").split()))
if stk: print("Popped:", stk.pop())

def question_22():
stk = []
def MakePush(): stk.append([input("ID: "), input("Desc: "), float(input("Weight: "))])
def MakePop():
if stk: print("Popped:", stk.pop())

question_functions = [None, question_1, question_2, question_3, question_4, question_5, question_6, question_7, question_8, question_9, q

def main():
while True:
print("\nMenu:")
for i in range(1, 23):
print(f"{i}. Question {i}")
print("0. Exit")
ch = int(input("Enter choice: "))
if ch == 0:
break
elif 1 <= ch <= 22:
question_functions[ch]()
else:
print("Invalid")

if __name__ == '__main__':
main()

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/ipython-input-4032269305.py in <cell line: 0>()
6
7
----> 8 question_functions = [None, question_1, question_2, question_3, question_4, question_5, question_6, question_7, question_8,
question_9, question_10, question_11, question_12, question_13, question_14, question_15, question_16, question_17, question_18,
question_19, question_20, question_21, question_22]
9
10 def main():

NameError: name 'question_6' is not defined

Next steps: Explain error

https://colab.research.google.com/drive/1HZ97GLBElmMrF_iz28rZuZ8gn6zsQ3f7?authuser=2#scrollTo=wQAd3K-zZSWS&printMode=true 5/6
8/20/25, 10:22 PM all_questions_notebook.ipynb - Colab
question_functions = [None, question_1, question_2, question_3, question_4, question_5, question_6, question_7, question_8, question_9,

def main():
while True:
print("\nMenu:")
for i in range(1, 23):
print(f"{i}. Question {i}")
print("0. Exit")
ch = int(input("Enter choice: "))
if ch == 0:
break
elif 1 <= ch <= 22:
question_functions[ch]()
else:
print("Invalid")

if __name__ == '__main__':
main()

https://colab.research.google.com/drive/1HZ97GLBElmMrF_iz28rZuZ8gn6zsQ3f7?authuser=2#scrollTo=wQAd3K-zZSWS&printMode=true 6/6

You might also like