Module1: Question Bank: Syllabus: Why Should You Learn To Write Programs, Variables, Expressions and Statements

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Module1: Question Bank

Syllabus: Why should you learn to write programs, Variables, expressions and statements,
Conditional execution, Functions?

Part A: Theory

1. a. Discuss with example and diagrams, Why Should you learn to write Programs?
b. Define Program. Differentiate between Compiler and Interpreter. Give Examples.
c. With a neat diagram explain the High level definition of the parts of Hardware Architecture. Explain
the role/Job of Programmer.
2. a. With examples explain the following Six Building blocks of Programs: Input, Output, Sequential
Execution, Conditional Execution, Repeated Execution and Reuse.
b. Explain the following different types of errors: Syntax errors, Semantic errors and Logic Errors.
3. Define the following with example : Values and Types , Variables , Expressions , Keywords ,
Statements , Operators and Operands, Order of Operations , Modulus Operators , String operations
and Comments.
4. Explain how to read the input from the user with example.
5. Explain the following with examples
a. Boolean Expression
b. Logical Operators
c. Conditional Execution : if
d. Alternative Execution: if else
e. Chained Conditionals : if elif else
f. Nested Conditionals : if else if else
g. Catching exception using try and except
h. Short circuit evaluation of logical circuits
6. Explain the following with example
a. Functions
b. Function Call
c. Built in Function
d. Type Conversion Functions
e. Random Numbers
f. Math Functions
g. Adding new Functions
h. Defining and using the new functions
i. Flow of execution
j. Parameter and Arguments
k. Fruitful and void Functions
l. Advantages of Functions
Part B: Programs

1. Write a program that uses input to prompt a user for their name and then welcomes them.
2. Write a program to prompt the user for hours and rate per hour to compute gross pay.
3. Write a program to read the following input from user and display
a. Name :
b. USN :
c. Roll NO:
d. Mobile No:
e. E-Mail id :
f. Percentage of Marks :
4. To find the simple interest for a given value P,T and R. The program must take the input from the
user.
5. To read two integers and find the sum , diff , mult and div .
6. To check whether the number is positive using simple if .
7. To check whether the given number is even or odd using simple if else.
8. Write a program to prompt the user for hours and rate per hour to compute gross pay. Also to give
the employee 1.5 times the hourly rate for hours worked above 40 hours.

Question Bank Module2


7. Define Iteration and Loop. With Syntax and Programming example explain the working and flow
execution of 1. While Loop and 2. For Loop in Python. Explain what are Minimum and Maximum Loops.
8. Define String? Explain how the strings are accessed , traversed, sliced and why Strings are called
immutable. Explain at least 5 String functions with examples. (concatenation, len, upper, lower, etc).
9. What are Files? Explain with syntax how the following file operations are done in Python :
a. Opening a File (existing)
b. Reading a File (existing)
c. Closing a File
d. Writing a File (existing)
e. Checking a current position
f. Reposition a pointer to the beginning
g. Creating and writing a new file
10. Write a python program to generate first n Fibonacci number and factorial of n using functions
11. Write a python program to count the number of Characters in a given string and hence to display
the characters of string in reverse order.
12. Write a python program to
a. To create two new files f1 and f2
b. To read and display the contents , count the number of lines and find the word whose
count is more in f1 and f2 respectively.
c. To create and display the file f3 which is a combination of f1 and f2.

Question Bank Of Module 3


1. What are Lists? Explain with examples the different ways to create a list. Why lists are called
Mutable. Discuss the following List operations and functions with examples :
1. Accessing ,Traversing and Slicing the List Elements
2. + (concatenation) and * (Repetition)
3. append , extend , sort , remove and delete
4. len , sum, min and max
5. split and join
2. Write a program to compute an average : 1) without using list and 2) using list
3. Compare String and List with examples. With example illustrate how the list can be passed as
arguments. What are objects and Aliasing?
4. What are Dictionaries? Explain with examples how the dictionaries are created. Differentiate
between Key and value of the Dictionary element. Mention the properties of Key . Discuss the
following Dictionary operations and functions with examples
1. Accessing , Traversing , Updating , Deleting
2. Traversing a Dictionary using looping
5. With example program illustrate how the Dictionary can be used to count the occurrence of
words in a file.
6. What are Tuples ? Explain with examples how tuples are created. Compare Tuple with list.
Discuss the following Dictionary operations and functions with examples
1. Accessing , Updating , Deleting , Traversing (Iteration) , Comparing
2. len ,(in) membership + (concatenation) and * (Repetition)
3. DSU (Decorate , Sort and UnDecorate ) pattern
7. Discuss the Tuple Assignment with example .Explain how swapping can be done using tuple
assignment. Write a Python program to input two integers a and b , and swap those numbers .
Print both input and swapped numbers.
8. With example explain how dictionary can be converted into tuple.
9. Write python program to find the common word in a given file. Accept the file name from the
user.
10. What are Regular Expressions? What are the two types of characters used in regular
expression? Give example. What are the common uses of regular expression?
11. Explain the intention/meaning of the following Regular expressions
1. ^From .* ([0-9][0-9]):
2. ^Details:.*rev=([0-9.]+
3. ^X\S*: ([0-9.]+)
4. ^X\S*: [0-9.]+
5. ^X\S*: [0-9.]+
6. [a-zA-Z0-9]\S+@\S+[a-zA-Z]
7. \S+@\S+
8. ^From:.+@
9. r"([a-zA-Z]+) (\d+)"
10. r"(\w+) World"
11. r'(.*) are (.*?) .*'
12. python
13. [Pp]ython
14. rub[ye]
15. [0-9]
16. [a-z]
17. [a-zA-Z0-9]
18. [^aeiou]
19. ruby?
20. ruby*
21. ruby+
22. \d{3}
23. \d{3,}
24. \d{3,5}

12. Explain the following methods of python regular expression library with programming examples.
1. re.match()
2. re.search()
3. re.findall()
4. re.split()
13. Explain with example the significance of Escape character in Regular Expression.
14. Briefly describe the methods of regular expression
15. What is list in Python? Demonstrate use of any three methods of list.
16. Give the output of following Python code: l=[(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
print l
17. Give the output of following Python code:
str1 = ‘This is Pyhton’
print( "Slice of String : ", str1[1 : 4 : 1] )
print("Slice of String : ", str1[0 : -1 : 2])

18. Is tuple mutable? Demonstrate any two methods of tuple.


19. What is dictionary in Python? Explain with an example
20. What is dictionary in Python? Explain with an example.
21. What is Lambda function give example.
22. Write a Python program to sum all the items in a list.
23. Write a Python program to get the largest and smallest number from a list.
24. Write a Python program to count the number of strings where the string length is 2 or
more and the first and last character are same from a given list of strings. Sample List :
['abc', 'xyz', 'aba', '1221']
Expected Result : 2

25. Write a Python program to convert a list of characters into a string.


26. Write a Python program to find the index of an item in a specified list.
27. Write a Python program to get the frequency of the elements in a list.
28. Write a Python program to create a list by concatenating a given list which range goes
from 1 to n.
Sample list : ['p', 'q']
n =5
Sample Output : ['p1', 'q1', 'p2', 'q2', 'p3', 'q3', 'p4', 'q4', 'p5', 'q5']
29. Write a Python program to convert list to list of dictionaries. Go to the editor
Sample lists: ["Black", "Red", "Maroon", "Yellow"], ["#000000", "#FF0000",
"#800000", "#FFFF00"]
Expected Output: [{'color_name': 'Black', 'color_code': '#000000'}, {'color_name': 'Red',
'color_code': '#FF0000'}, {'color_name': 'Maroon', 'color_code': '#800000'},
{'color_name': 'Yellow', 'color_code': '#FFFF00'}]
Click me to see the sample solution
30. Write a Python program to create a list of empty dictionaries.
31. Write a Python program to access dictionary keys element by index.
32. Write a Python program to iterate over dictionaries using for loops
33. Write a Python program to sum all the items in a dictionary.
34. Write a Python script to concatenate following dictionaries to create a new one.
Sample Dictionary :
dic1={1:10, 2:20}
dic2={3:30, 4:40}
dic3={5:50,6:60}
Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
35. Write a Python program to create a tuple
36. Write a Python program to create a tuple with different data types
37. Write a Python program to convert a tuple to a string
38. Write a Python program to slice a tuple
39. Write a Python program to find the length of a tuple.
40. Write a Python program to convert a tuple to a dictionary.
41. Write a Python program to reverse a tuple
42. Write a Python program to convert a list of tuples into a dictionary
43. Write a Python program to convert a list to a tuple.

Question Bank Module 4


Question Bank Of Module 4

1. Define Class and Object.


2. With syntax and programming example, explain how the class is defined, object is created,
and methods are invoked in Python.
3. With illustration Discuss the use of __init__ method in Python.
4. Why Objects are mutable.
5. Explain the use of copy module in Python.
6. With an example explain how the objects can be modified using functions.
7. Explain the following two types of functions with an example
a. Pure Function
b. Modifiers
8. With help of programming examples explain the difference between Prototype and Planned
Programming Development.
9. Explain with example the following features of object-oriented programming languages
c. Class and Object
d. Data Variables and Methods
e. Encapsulation
f. Inheritance
g. Polymorphism
h. Operator Overloading
i. Operator Overriding
10. What is the difference between functions and methods. With example explain how to
transform functions into methods.
11. Explain with example what are optional arguments.
12. Explain with example what is initialization method. With programming example illustrate the
use of initialization method and self-argument.
13. Write an Object-Oriented Python program to create two Time objects: current Time, which
contains the current time; and bread Time, which contains the amount of time it takes for a
bread maker to make bread. Then we'll use add Time to figure out when the bread will be
done. Write the print Time function to display the time when the bread will be done by the
bread maker.
14. Design a Python program as described below:
j. Create a class called Palindrome.
k. In your Palindrome class, create a method called reverse() which takes a string
argument. Your method should return the reverse of the argument as a string.
l. Create a second method in Palindrome called isPalindrome() which takes a string
argument. This method should return True if the argument is a palindrome and
False otherwise.
m. Write some code to test your new Palindrome class and print out results of your
testing to the user. Give some consideration to what sort of strings you might
want to use for your testing.

Additional Questions
1.Create a student database using dictionary. Read rollnumber, name and mark in
computer programming. Use rollnumber as key and the other data must be stored as
list.List the students details in the order of roll number. Read a roll number and display
the corresponding student details.Delete a particular student details after reading a roll
number.

2.Read a list of numbers and print the count of each element in the list in the order.

3.Read a string and print the number of occurrence of vowels in the string.

4.Empno, name and basic pay of ‘n’ employees are stored in a dictionary. Use empno as
the key. Read an empno and update the basic pay of that employee.

5.In the above program display the name and basic pay of all the employees in the order
of name.

6.Read an octal number( as string) and convert into binary using a dictionary.

7. Write a python program to create a dictionary of roll numbers and names of five
students. Display the content of the dictionary in the alphabetical order of names.(
University Question)

8.A bookshop details contains the Title of the book and Number of copies of each title. As
books are added to the shop, the number of copies to each should increase and as books
are sold, the number of copies in each should decrease. Implement this scenario using
dictionary data type in Python. (University Question)

9.Read a list of marks(out of 20).Count the three category of students fail(f), pass(p),
firstclass(fc).
10.Read a string and find the characters which occurred most, also print their count.

11.Represent a sparse matrix using dictionary. ( refer sample program)

12. Program to count the number of occurrence(frequency) of each letters in a given string(
histogram

13. Program to read name and phn numbers of ‘n’ customers and print the list in sorted order
of names
14.Create a class car with attributes model, year and price and a method cost() for
displaying the prize. Create two instance of the class and call the method for each
instance

15.Create a class student with attribute name and roll number and a method dataprint()
for displaying the same. Create two instance of the class and call the method for each
instance

16.Create a class Person with attributes name, age salary and a method display() for
showing the details. Create two instances of the class and call the method for each
instance.

17.Create a class Rectangle with attributes length and breadth and method area() for
calculating the area of the rectangle. Create two instances of the class and call the method
for each instance.

18.Create a class car with attributes model, year and price and a method cost() for
displaying the prize. Create two instance of the class and call the method for each
instance.

19.Create a class student with attribute name and roll number and a method dataprint()
for displaying the same. Create two instance of the class and call the method for each
instance.

20.Create a class Person with attributes name, age, salary and a method display() for
showing the details. Create two instances of the class and call the method for each
instance.

21.Create a class Employee with attributes name, age and salary and a method
printdetails() for displaying the same. Create two instances of the class and call the
method for each instance.
Question Bank Module 5

1. What is Socket? Explain the Socket Module. Explain with syntax how sockets are
created in Python using Socket address , Socket types and Port Number.
2. Explain Server Sockets Methods , Client Sockets and General Socket Methods.
3. What is Client and Server? Write a Python program to create client and server.
4. What is Port? List out Well Known Ports and their applications and protocol.
5. Define WebScraping
6. Write a short note on the following :
a. Socket
b. Port
c. HTTP
d. WebBrowser
7. Write and Explain the Program of Simple Web Browser.
8. Write and explain the program to retrieve an image over HTTP.
9. Write and Explain the python program to retrieve web pages with urllib.
10. Write a python program to retrieve the data from the text file (containing English
sentences) and compute the frequency of each word.
11. Describe Parsing HTML and Scraping the web.
12. Write and Explain Python program to parse HTML using regular expressions.
13. Write and Explain Python Program to parse HTML using Beutifulsoup Library.
14. Write and Explain Python Program to read binary files using urllib.
15. What is XML? What are the applications of XML? Differentiate between XML and
HTML.
16. What are the features and advantages of XML?
17. Give example for XML and Write a Tree representation of XML.
18. With example explain the Tree Structure of XML.
19. Write and Explain Python Program to parse XML.
20. What is JSON? Explain with Example.
21. Write and Explain Python Program to parse JSON.
22. Write a brief note on Application Programming Interfaces (API).
23. With example explain SOA.
24. What is Google Geocoding Services ? Write and Explain Python Program to
prompt user for a search string (city) , call the Geocoding API and extracting
information from the returned XML.
25. Explain how security is achieved in API usage.
26. Define Data, Database , Table , Rows and Columns.
27. Write and Explain Python Program to create a Database Table.
28. Explain what is Database Cursor.
29. Explain spidering a twitter.
30. Write and Explain Python Program to spidering twitter to a database with single
table.
31. Explain what is Data Modeling.
32. Write and Explain Python Program to spidering twitter data into Multiple Tables.
Or Write and Explain Python Program to retrieve data from twitter account
/database and to insert a data to a database with multiple tables..

You might also like