0% found this document useful (0 votes)
762 views

18CS55 ADP Question Bank Module 3, 4 and 5

This document contains a question bank and past VTU exam questions for the subject "Application Development using Python" for Module 3, 4 and 5 covering topics like lists, tuples, dictionaries, regular expressions, classes and objects, inheritance, operator overloading, file handling and web scraping. It includes 20 questions for Module 3 on lists, tuples, dictionaries and regular expressions. 15 questions for Module 4 on classes and objects, inheritance and operator overloading. And 12 questions for Module 5 covering topics in web scraping like the differences between various modules, making HTTP requests, parsing responses using Beautiful Soup and interacting with browsers.

Uploaded by

Palguni DS
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)
762 views

18CS55 ADP Question Bank Module 3, 4 and 5

This document contains a question bank and past VTU exam questions for the subject "Application Development using Python" for Module 3, 4 and 5 covering topics like lists, tuples, dictionaries, regular expressions, classes and objects, inheritance, operator overloading, file handling and web scraping. It includes 20 questions for Module 3 on lists, tuples, dictionaries and regular expressions. 15 questions for Module 4 on classes and objects, inheritance and operator overloading. And 12 questions for Module 5 covering topics in web scraping like the differences between various modules, making HTTP requests, parsing responses using Beautiful Soup and interacting with browsers.

Uploaded by

Palguni DS
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/ 5

Department of Computer Science & Engineering

Date: 11-11-2021

Question Bank and VTU Exam Questions (Module 3, 4 and 5)

Subject: Application Development using Python (18CS55) Semester: 5


Scheme: 2018

Module 3: [TB 1: Chapter 9 and 10]

1. What are Lists? List are mutable. Justify the statement with examples. [June 2018]
2. How tuples are created in Python? Explain different ways of accessing and creating them.
[June 2018]
3. Write a Python program to read all the lines in a file accepted from the user and print all email
addresses contained in it. Assume the email addresses contain only non-white space characters.
[June 2018]
4. Implement a Python program using List to store and display the average of N integers accepted from
the user. [June 2018]
5. Explain dictionaries. Demonstrate with a Python program. [June 2018]
6. Write a Python program to search for lines that start with the word 'From' and a character followed
by a two digit number between 00 and 99 followed by ':' Print the number if it is greater than zero.
Assume any input file. [June 2018]
7. Describe any two list operations and list methods. Write a python program to accept 'n' numbers
from user, find sum all even numbers and product of all odd numbers in entered list. [Dec 2018]
8. List merits of dictionary over list. Write a python program to accept USN and marks obtained,
find maximum, minimum and students USN who have scored in the range 100-85,85-75,75-60 and
below 60 marks separately. [Dec 2018]
9. Compare and contrast tupules with lists. Explain the following operations in tupules
a. Sum of two tupules
b. Slicing operators
c. Compression of two tupules
d. Assignment to variables. [Dec 2018]
10. Explain extracting data using regular expressions. Implement a python program to find for files
having ‘@’ sign between characters in a read text file. [Dec 2018]

Organizing Files
11. What is the difference between shutil.copy() and shutil.copytree()?
12. What function is used to rename files?
13. What is the difference between the delete functions in the send2trash and shutil modules?
14. ZipFile objects have a close() method just like File objects’ close() method. What ZipFile method is
equivalent to File objects’ open() method?
15. Explain the following functions with examples.
shutil.copy(source, destination)
shutil.copytree(source, destination)
shutil.move(source, destination)
os.unlink(path)
os.rmdir(path)

Debugging
16. Write an assert statement that triggers an AssertionError if the variable spam is an integer less than
10.
17. What are the two lines that your program must have in order to be able to call logging.debug()?
18. What are the five logging levels?
19. What line of code can you add to disable all logging messages in your program?
20. Explain Assertions with examples.

Module 4: Classes and objects, Classes and functions, Classes and methods
[TB 2: Chapter 15 – 17]
1. How class can be instantiated in python? Write a program to express instances as return
values to define a class RECTANGLE with members width, height and corner_x, corner_y
and member functions: to find center, area of a rectangle. [Dec 2018]
2. Explain init and str methods with an example python program. [Dec 2018]
3. Define polymorphism. Demonstrate polymorphism with function to find histogram to count
the number of times each letter appears in a word and sentence. [Dec 2018]
4. What is pure function? Write a python program to find duration of event if start and end
time is given by defining class TIME. [Dec 2018]
5. Create a student class and initialize it with name and roll number. Design methods to:
a. display: to display all information of the student.
b. setAge: to assign age to student.
c. setMarks: to assign marks to the student. [June 2018]
6. Using datetime module write a program that gets a current date and prints the day of the week.
[June 2018]
7. What are polymorphic functions? Explain with a snippet code. [June 2018]
8. What does the keyword self in python mean? Explain with an explain. [June 2018]
9. Show using a python code how init method is invoked when an object is initiated. Explain its
working. [June 2018]
10. Explain _str_ method with a python program. [June 2018]
11. Explain operator overloading with example.
12. Write a python program to define class Rectangle with members width, height and corner_x,
corner_y and member functions to find center of rectangle, and area of a rectangle.
Demonstrate usage of all the functions.
13. Write a python program
a. to find duration of event if start and end time is given, by defining class TIME.
b. to increment TIME object. [use integer to store time]

Chapter 15: Classes and objects


Exercise 1
Write a function called distance_between_points that takes two Points as arguments and returns the
distance between them.

Exercise 2
Write a function named move_rectangle that takes a Rectangle and two numbers named dx and dy. It
should change the location of the rectangle by adding dx to the x coordinate of corner and adding dy to
the y coordinate of corner.

Exercise 3
Write a version of move_rectangle that creates and returns a new Rectangle instead of modifying the
old one.
Soln: ch15_e1_e2_e3.py

Chapter 16: Classes and functions


Exercise 1
Write a function called print_time that takes a Time object and prints it in the form hour:minute:second.
Hint: the format sequence '%.2d' prints an integer using at least two digits, including a leading zero if
necessary.
Soln: ch16_e1.py

Exercise 2
Write a boolean function called is_after that takes two Time objects, t1 and t2, and
returns True if t1 follows t2 chronologically and False otherwise. (Avoid if statement)
Soln: ch16_e2.py

Exercise 3
Write a correct version of increment that doesn’t contain any loops.
Soln: ch16_e3.py

Exercise 4
Write a “pure” version of increment that creates and returns a new Time object rather than modifying the
parameter.

Exercise 5
Rewrite increment using time_to_int and int_to_time.

Chapter 17: Classes and methods


Exercise 1
Rewrite time_to_int (from Section 16.4) as a method. It is probably not appropriate to
rewrite int_to_time as a method; what object you would invoke it on?

Exercise 2
Write an init method for the Point class that takes x and y as optional parameters and assigns them to
the corresponding attributes.

Exercise 3 Write a str method for the Point class. Create a Point object and print it.
Exercise 4 Write an add method for the Point class.

Exercise 5
Write an add method for Points that works with either a Point object or a tuple:
 If the second operand is a Point, the method should return a new Point whose xcoordinate is the
sum of the x coordinates of the operands, and likewise for the ycoordinates.
 If the second operand is a tuple, the method should add the first element of the tuple to
the x coordinate and the second element to the y coordinate, and return a new Point with the
result.
Exercise 6
Download the code from this chapter (http://thinkpython.com/code/Time2.py). Change the attributes
of Time to be a single integer representing seconds since midnight. Then modify the methods (and the
function int_to_time) to work with the new implementation. You should not have to modify the test
code in main. When you are done, the output should be the same as before.
Solution: http://thinkpython.com/code/Time2_soln.py

Module 5
Chapter 11: Web Scraping
1. Briefly describe the differences between the webbrowser, requests, BeautifulSoup, and selenium
modules.
2. What type of object is returned by requests.get()? How can you access the downloaded content as a
string value?
3. What Requests method checks that the download worked? Give example.
4. How can you get the HTTP status code of a Requests response?
5. How do you save a Requests response to a file?
6. What is the keyboard shortcut for opening a browser’s developer tools?
7. How can you view (in the developer tools) the HTML of a specific element on a web page?
8. What is the CSS selector string that would find the element with an id attribute of main?
9. What is the CSS selector string that would find the elements with a CSS class of highlight?
10. What is the CSS selector string that would find all the <div> elements inside another <div> element?
11. What is the CSS selector string that would find the <button> element with a value attribute set to
favorite?
12. Say you have a Beautiful Soup Tag object stored in the variable spam for the element <div>Hello
world!</div>. How could you get a string 'Hello world!' from the Tag object?
13. How would you store all the attributes of a Beautiful Soup Tag object in a variable named linkElem?
14. Running import selenium doesn’t work. How do you properly import the selenium module?
15. What’s the difference between the find_element_* and find_elements_* methods?
16. What methods do Selenium’s WebElement objects have for simulating mouse clicks and keyboard
keys?
17. You could call send_keys(Keys.ENTER) on the Submit button’s WebElement object, but what is an
easier way to submit a form with Selenium?
18. How can you simulate clicking a browser’s Forward, Back, and Refresh buttons with Selenium?

Chapter 12: Working with Excel Spreadsheets


For the following questions, imagine you have a Workbook object in the variable wb, a Worksheet object
in sheet, a Cell object in cell, a Comment object in comm, and an Image object in img.
1. What does the openpyxl.load_workbook() function return?
2. What does the get_sheet_names() workbook method return?
3. How would you retrieve the Worksheet object for a sheet named 'Sheet1'?
4. How would you retrieve the Worksheet object for the workbook’s active sheet?
5. How would you retrieve the value in the cell C5?
6. How would you set the value in the cell C5 to "Hello"?
7. How would you retrieve the cell’s row and column as integers?
8. What do the get_highest_column() and get_highest_row() sheet methods return, and what is the data
type of these return values?
9. If you needed to get the integer index for column 'M', what function would you need to call?
10. If you needed to get the string name for column 14, what function would you need to call?
11. How can you retrieve a tuple of all the Cell objects from A1 to F1?
12. How would you save the workbook to the filename example.xlsx?
13. How do you set a formula in a cell?
14. If you want to retrieve the result of a cell’s formula instead of the cell’s formula itself, what must you
do first?
15. How would you set the height of row 5 to 100?

Chapter 13: Working with PDF and Word Documents .


1. A string value of the PDF filename is not passed to the PyPDF2.PdfFileReader() function. What do you
pass to the function instead?
2. What modes do the File objects for PdfFileReader() and PdfFileWriter() need to be opened in?
3. How do you acquire a Page object for page 5 from a PdfFileReader object?
4. What PdfFileReader variable stores the number of pages in the PDF document?
5. If a PdfFileReader object’s PDF is encrypted with the password swordfish, what must you do before you
can obtain Page objects from it?
6. What methods do you use to rotate a page?
7. What method returns a Document object for a file named demo.docx?
8. What is the difference between a Paragraph object and a Run object?
9. How do you obtain a list of Paragraph objects for a Document object that’s stored in a variable named
doc?
10. What type of object has bold, underline, italic, strike, and outline variables?
11. What is the difference between setting the bold variable to True, False, or None?
12. How do you create a Document object for a new Word document?
13. How do you add a paragraph with the text 'Hello there!' to a Document object stored in a variable
named doc?

Chapter 14: Working with CSV Files and JSON Data


1. What are some features Excel spreadsheets have that CSV spreadsheets don’t?
2. What do you pass to csv.reader() and csv.writer() to create Reader and Writer objects?
3. What modes do File objects for reader and Writer objects need to be opened in?
4. What method takes a list argument and writes it to a CSV file?
5. What do the delimiter and lineterminator keyword arguments do?
6. What function takes a string of JSON data and returns a Python data structure?
7. What function takes a Python data structure and returns a string of JSON data?

*****

You might also like