Python
Python
2-Mark Questions:
1. What is the difference between Python’s interactive mode and script mode?
2. Define identifiers and keywords in Python.
3. What is the purpose of comments in Python?
4. List the primary data types in Python.
5. What is a lambda function? How does it differ from a regular function?
6. Give examples of conditional statements in Python.
7. What is the difference between break and continue in loops?
Big Questions:
2-Mark Questions:
Big Questions:
1. Discuss the differences between mutable and immutable data structures in Python.
2. Explain and implement Kadane’s Algorithm in Python.
3. Write a program for the Dutch National Flag Algorithm.
4. Demonstrate dictionary operations with examples.
2-Mark Questions:
2-Mark Questions:
Big Questions:
2-Mark Questions:
Big Questions:
1. Write a program to calculate EMI for a loan based on user input (principal, interest
rate, tenure).
2. Develop a Python program to detect all vowels in a string that are "sandwiched"
between non-vowel characters.
3. Create a Python program to implement a simple Chocolate Distribution Algorithm to
minimize the difference between the maximum and minimum chocolates given.
4. Write a Python program to demonstrate the use of lambda functions by sorting a list
of tuples based on the second element.
5. Write a Python program to find the factorial of a number using a fruitful function.
6. Write a Python program to implement the Dutch National Flag Algorithm to sort an
array of 0s, 1s, and 2s.
7. Create a program to demonstrate tuple unpacking and tuple as a return value.
8. Write a Python program to perform dictionary operations: adding, updating, deleting,
and searching keys/values.
9. Implement a Python program to find the union, intersection, and difference of two
sets.
10. Develop a program to solve the Count and Say problem.
11. Write a Python program to find the maximum sum of a contiguous subarray using
Kadane’s Algorithm.
19. Write a Python program using NumPy to calculate the sum, mean, and standard
deviation of an array.
20. Develop a program in Pandas to:
o Create a DataFrame.
o Perform operations such as data indexing, selection, and handling missing
values.
21. Use Matplotlib to:
o Create a simple line plot.
o Generate a scatter plot to visualize data points.
22. Design a simple webpage in Django that includes a form to collect user data (name
and email).
23. Create a Python program to generate a box plot and a bar plot for given data using
Matplotlib.
python
Copy code
def calculate_emi(principal, rate, time):
rate = rate / (12 * 100) # Monthly interest rate
time = time * 12 # Convert years to months
emi = (principal * rate * ((1 + rate) ** time)) / (((1 + rate) ** time)
- 1)
return round(emi, 2)
python
Copy code
def is_vowel(char):
return char.lower() in 'aeiou'
def sandwich_vowel(s):
result = []
for i in range(1, len(s) - 1):
if is_vowel(s[i]) and not is_vowel(s[i - 1]) and not is_vowel(s[i +
1]):
result.append(s[i])
return result
python
Copy code
def dutch_national_flag(arr):
low, mid, high = 0, 0, len(arr) - 1
while mid <= high:
if arr[mid] == 0:
arr[low], arr[mid] = arr[mid], arr[low]
low += 1
mid += 1
elif arr[mid] == 1:
mid += 1
else:
arr[mid], arr[high] = arr[high], arr[mid]
high -= 1
return arr
arr = [2, 0, 1, 2, 1, 0]
print("Sorted Array:", dutch_national_flag(arr))
Kadane’s Algorithm
python
Copy code
def max_subarray_sum(arr):
max_sum = float('-inf')
current_sum = 0
for num in arr:
current_sum = max(num, current_sum + num)
max_sum = max(max_sum, current_sum)
return max_sum
def view_accounts():
with open("bank_accounts.txt", "r") as f:
print("Account Details:")
print(f.read())
python
Copy code
from pymongo import MongoClient
# MongoDB connection
client = MongoClient("mongodb://localhost:27017/")
db = client['mydatabase']
collection = db['mycollection']
# Create
def create_document(data):
collection.insert_one(data)
print("Document inserted successfully.")
# Read
def read_documents():
for doc in collection.find():
print(doc)
# Update
def update_document(filter_query, new_values):
collection.update_one(filter_query, {'$set': new_values})
print("Document updated successfully.")
# Delete
def delete_document(filter_query):
collection.delete_one(filter_query)
print("Document deleted successfully.")
# Example usage
create_document({"name": "John", "age": 30})
read_documents()
update_document({"name": "John"}, {"age": 35})
delete_document({"name": "John"})
python
Copy code
import matplotlib.pyplot as plt
# Example data
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 25, 30]
# Line plot
plt.plot(x, y, label="Performance")
plt.xlabel("Time")
plt.ylabel("Value")
plt.title("Performance Analysis")
plt.legend()
plt.show()
html
Copy code
<!-- form.html -->
<!DOCTYPE html>
<html>
<head>
<title>Simple Form</title>
</head>
<body>
<h2>Simple Form</h2>
<form action="/submit/" method="post">
{% csrf_token %}
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>