0% found this document useful (0 votes)
7 views3 pages

BCC402 Assignment 2 (Due Date: 19 July 2024)

This document is an assignment outline for BCC402, consisting of 40 questions related to Python programming, data manipulation, and object-oriented programming concepts. It includes tasks such as defining functions, creating classes, and utilizing libraries like NumPy and Pandas. The assignment is due on July 19, 2024.

Uploaded by

mithusitu21
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)
7 views3 pages

BCC402 Assignment 2 (Due Date: 19 July 2024)

This document is an assignment outline for BCC402, consisting of 40 questions related to Python programming, data manipulation, and object-oriented programming concepts. It includes tasks such as defining functions, creating classes, and utilizing libraries like NumPy and Pandas. The assignment is due on July 19, 2024.

Uploaded by

mithusitu21
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/ 3

BCC402

Assignment 2
(Due date: 19th July 2024)

Q1: Define String. Write a Python function that takes a string as input and returns the string with all
vowels removed.
Q2. Given a list of integers, write a Python function that returns a new list containing only the even-
indexed elements of the original list.

Q3. Explain the difference between a list and a tuple in Python. Provide an example where a tuple
would be preferred over a list.

Q4. Write a Python function that counts the number of times a specific substring appears in a given
string.

Q5. Write a Python function that takes a list of integers and returns a new list with each element
squared.

Q6. Given a dictionary where keys are student names and values are their grades, write a Python
function that returns the name of the student with the highest grade.

Q7. Write a Python function that takes a string and returns a dictionary where the keys are the unique
characters in the string and the values are the number of times each character appears.

Q8. Write a Python program to sort a list of tuples based on the second element of each tuple using an
in-built function.

Q9. Define a Python function that calculates the factorial of a given number using recursion.

Q10. Write a Python program that reads a list of words from a file and prints out a list of the words
sorted by length. Use functions to organize your code.

Q11. Write a Python function that reads the entire content of a file and prints it to the console.

Q12. Write a Python function that writes a list of strings to a file, with each string on a new line.

Q13. Explain what the read() function does in Python and provide an example of how to use it.

Q14. Write a Python function that reads a file line by line using the readline() function and prints
each line.

Q15. Write a Python function that reads all the lines of a file into a list using the readlines() function
and returns this list.

Q16. Explain the difference between the write() and writelines() functions in Python. Provide an
example of how to use each one.
Q17. Write a Python function that demonstrates how to use the seek() function to move the file
pointer to the beginning of a file and then read the first 10 characters.

Q18. Write a Python function that reads a file and then writes its content to a new file in reverse order.

Q19. Write a Python program that reads a file, counts the number of words, and writes the word count
to a new file.

Q20. Write a Python function that attempts to read from a file and handles the FileNotFoundError
exception by printing an appropriate message.

Q21. Define a class Person with attributes name and age. Write a method display_info() that prints
the person's name and age.

Q22. Explain the purpose of the __init__ method in a Python class. Create a class Car with attributes
make, model, and year, and include an __init__ method to initialize these attributes.

Q23. Write a class Rectangle with attributes length and width. Include methods to calculate the area
and perimeter of the rectangle.

Q24. Explain the difference between a class method and a static method. Create a class
MathOperations with a class method to add two numbers and a static method to multiply two
numbers.

Q25. Create a base class Animal with a method speak(). Create a derived class Dog that overrides the
speak() method to print "Bark!".

Q26. Explain the concept of encapsulation in object-oriented programming. Create a class


BankAccount with private attributes account_number and balance. Provide public methods to deposit
and withdraw money from the account.

Q27. Write a base class Shape with a method area(). Create two derived classes Circle and Square that
override the area() method to calculate the area of a circle and a square, respectively.

Q28. Create a class Student with attributes name and grade. Use the __init__ method to initialize
these attributes when an object of the class is created. Instantiate the class and print the attributes.

Q28. Define a class Book with attributes title, author, and pages. Override the __str__ method to
return a string in the format "Title: <title>, Author: <author>, Pages: <pages>". Instantiate the class
and print the object.

Q29. Create a function that validates an email address and raises a custom exception
InvalidEmailError if the email is not valid. Write a try-except block to handle this exception and print
an appropriate message.

Q30. Write a NumPy program to create an array of 10 zeros, an array of 10 ones, and an array of 10
fives. Display these arrays.

Q31. Create a NumPy array of shape (3, 3) filled with random values. Write a function to replace the
maximum value of each row with 0.

Q32. Write a NumPy program to compute the multiplication of two given matrices.
Q33. Create a NumPy array of 100 random numbers and write a function to compute the mean,
median, and standard deviation of the array.

Q34. Create a Pandas DataFrame from a dictionary of lists. Perform basic operations like renaming
columns, adding a new column, and deleting a column.

Q35. Write a Pandas program to read a CSV file, handle missing data by replacing them with the
column mean, and display the first 10 rows of the cleaned DataFrame.

Q36. Create a Pandas DataFrame and use the groupby function to group the data by one of the
columns. Perform aggregation operations like sum, mean, and count on the grouped data.

Q37. Write a Pandas program to merge two DataFrames based on a common column. Demonstrate
inner, outer, left, and right joins.

Q38. Write a Python script using Matplotlib to plot a line graph of the function y = x^2 for x values
ranging from -10 to 10. Add titles and labels to the axes.

Q39. Write a Python script using Matplotlib to create a bar graph displaying the number of students in
different classes (e.g., Class A: 30, Class B: 25, Class C: 35). Add labels to the x-axis, y-axis, and a
title.

Q40. Create a scatter plot showing the relationship between the height and weight of individuals. Use
different colors to represent males and females, and use the size of the markers to represent age.

You might also like