east west institute of technology13. a number with more than one digit is input through the...

12
EAST WEST INSTITUTE OF TECHNOLOGY DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING QUESTION BANK COURSE NAME: PYTHON APPLICATION PROGRAMMING COURSE CODE: 15CS664 SEM: VI STAFF NAME: Mrs. MAMATHA B N Mrs. BHAVYA T ACADAMIC YEAR 2019-2020 ( EVEN SEM) MODULE 1: INTRODUCTION, VARIABLES, EXPRESSIONS AND STATEMENTS, CONDITIONAL EXECUTION, FUNCTIONS QUESTIONS 1. Explain the following: a.) Skills necessary for the programmer b.) Interactive mode c.) Short circuit evaluation of expression d.) Modulus operator Dec 2018/Jan 2019 2. Mention three types of error encountered in python programs. Explain the basic building blocks of python with an example to display format number (Fn = 2 2n +1) for a ‘n’ value prompted by the user . Dec 2018/Jan 2019 3. Describe python language support for arithmetic operators. What are operators and operands? Explain the rule of precedence. What is floored division? Dec 2018/Jan 2019 4. Write a python program to calculate student result based on two exams, one sport event and three activities conduced in a college with weigthtage of the activity= 20% and sports = 20% for 50 marks. Dec 2018/Jan 2019 5. List and give syntax of all python supported conditional statement along with its usage with an example program to check whether the given number is positive or negative or zero. Dec 2018/Jan 2019 6. Differentiate between argument and parameter. Illustrate the flow of execution of a python function with an example program to convert given Celsius to Fahrenheit temperature Dec 2018/Jan 2019 7. List the rules to declare variable in python. Demonstrate atleast three different types of variables with an example program. 8. Explain the rules of used by python to evaluate an expression. 9. Write a python program to find the best of two test average marks out of three test marks accepted from the user. 10. How python handles the exceptions? Explain the same with example program. 11.Write a single user defined function named ‘Solve’, that returns the reminder and quotient on division of two numbers accepted from the user, print the reminder and quotient separately on the console.

Upload: others

Post on 27-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

EAST WEST INSTITUTE OF TECHNOLOGY

DEPARTMENT OF INFORMATION SCIENCE & ENGINEERING

QUESTION BANK

COURSE

NAME: PYTHON APPLICATION

PROGRAMMING

COURSE CODE: 15CS664 SEM:

VI

STAFF

NAME:

Mrs. MAMATHA B N

Mrs. BHAVYA T

ACADAMIC YEAR 2019-2020 ( EVEN

SEM)

MODULE 1: INTRODUCTION, VARIABLES, EXPRESSIONS AND STATEMENTS,

CONDITIONAL EXECUTION, FUNCTIONS

QUESTIONS

1. Explain the following:

a.) Skills necessary for the programmer

b.) Interactive mode

c.) Short circuit evaluation of expression

d.) Modulus operator Dec 2018/Jan 2019

2. Mention three types of error encountered in python programs. Explain the basic building blocks of python

with an example to display format number (Fn = 22n+1) for a ‘n’ value prompted by the user.

Dec 2018/Jan 2019 3. Describe python language support for arithmetic operators. What are operators and operands? Explain the

rule of precedence. What is floored division?

Dec 2018/Jan 2019

4. Write a python program to calculate student result based on two exams, one sport event and three activities

conduced in a college with weigthtage of the activity= 20% and sports = 20% for 50 marks. Dec

2018/Jan 2019

5. List and give syntax of all python supported conditional statement along with its usage with an example

program to check whether the given number is positive or negative or zero.

Dec 2018/Jan 2019

6. Differentiate between argument and parameter. Illustrate the flow of execution of a python function with an

example program to convert given Celsius to Fahrenheit temperature Dec

2018/Jan 2019 7. List the rules to declare variable in python. Demonstrate atleast three different types of variables with an

example program.

8. Explain the rules of used by python to evaluate an expression.

9. Write a python program to find the best of two test average marks out of three test marks accepted from the

user.

10. How python handles the exceptions? Explain the same with example program.

11.Write a single user defined function named ‘Solve’, that returns the reminder and quotient on division of

two numbers accepted from the user, print the reminder and quotient separately on the console.

Page 2: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

12 .Predict the output and justify your answer

a. -11%9 b.) 7.7//7 c.) (200-70)*10/5 d.) Not”False” e.) 5*1**2

13. With a neat diagram explain the Computer hardware architecture. Explain each using an example of human

capability.

14. What are programs and two skills to be a good programmer? Explain the building blocks of programs.

(Program Constructs)

15. Explain the conversation with python.

16. What are interpreter and compiler? Explain how it works in python.

17.Difference between interpreter and compiler.

18. What will the following program print out:

x=43

x=x+1

print (x) 19. Design and construct a python program for the following(using functions and without functions):

a) To calculate the Fibonacci series for a given number.

b) To find the area of circle and rectangle.

c) To find the sum of the array elements.

d) To swap two number without using temporary variable.

e) To find whether given input is palindrome or not.

f) To find even and odd number for a given range.

g) To calculate Fahrenheit to Celsius for a given number.

20. What are variables? How to display the type of a variable. Explain the rules of variables with example. Explain

mnemonic variable names.

21. Describe python language support for arithmetic operators. What are operators and operands? Explain the rule of

precedence. What is floored division?

22. What is string? Explain string operations.

23. Explain how user will ask for input. Discuss the output for the following:

>>>Bad name=5

>>>principal=2222.33

>>>interest = princal * rate

>>>1.0/2.0 * pi

>>>x=5

>>> y=6

def fred():

print(“Zap”)

def jane():

print(“ABC”)

Page 3: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

jane()

fred()

jane()

24. Discuss Boolean expression and logical operators. Write briefly about short-circuit evaluation.

25. Briefly explain the function calls. Define and call a new function with and without parameters. Discuss the purpose

of functions

26. What is module? Discuss about Random and Math module along their functions

27. Write a function with 2 parameters(hours and rate) to calculate pay increased by 1.5 times for employee working

overtime(hours more than 40)

28. Write a program to prompt for a score between 0.0 and 1.0. if the score is out of range, print an error message. If

score is between 0.0 and 1.0 print a grade using the following table

Score Grade

>=0.9 A

>=0.8 B

>=0.7 C

>=0.6 D

<0.6 F 29. Discuss the following:

A. Type conversion functions

B. Fruitful and void functions

MODULE 2

ITERATION

1. Demonstrate the use of break and continue keyword in looping structures using a snippet code

6M

2. When and how to use while and for loop with syntax and example. 4M

3. Explain break and continue statements with examples in Python. Write Pythonic code that iteratively

prompts the user for input. It should continue until the user enters 'done!' and then return the average value.

8M

4. Write a Python program to compute only even numbers, sum within the given natural numbers using

continue statement 8M

5. Write a Python program to find the roots of a quadratic equation.

6. Write Pythonic code to multiply two matrices using nested loops and print the result.

7. What do you mean by iteration variable and infinite loop? Discuss unconditional statements with example.

8. Discuss ‘definite and infinite’ loops with example

Page 4: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

9. Without using inbuilt functions write a code segment to find the count, sum, minimum and maximum value

in a list.

10. Write a function which repeatedly reads numbers until user enters “done!!” Once done is entered print the

total, count and average of the numbers. If the user enters anything other than a number, detect their

mistake using try and except and print a error message and skip to next iteration.

11. Write a function that prompts for a list of numbers and print maximum and minimum among the entered

numbers without using built-in functions.

12. Write Pythonic code to find the factorial of any number entered through the keyboard.

13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits

in the number and find the sum of all the digits in the reversed number.

14. Write a Python Program to check whether a number is prime or not using while loop and print appropriate

messages.

15. Write a Python program to find average of best two test marks out of three test marks.

STRINGS

1. Explain string slicing in python, show with example. 4M

2. Define a string. How it traversed through using looping statements? Write a Python program to display

presence of given sub string in main string 8M

3. Write a python program to accept a sentence from user and display the longest word of that sentence along

with its length 6M

4. List and explain any four built in string manipulation functions supported by python 6M

5. Write a python code to display the last six character of the string “Make hay while the sun shines” to the

console 3M

6. What is a string? Develop a program to demonstrate traversal of string within loops (while and for).

7. Write a program to reverse a string.

8. Write a program to display all the palindrome words appearing in an input text.

9. “Strings in Python are immutable”. Explain this statement with example.

10. Write a while loop that starts at the last character in the string and works backward to the first character in

the string, print each character on a separate line.

11. Explain string slice. Justify how strings are immutable.

12. Develop the python program to prompt a string from user and print the number of times occurrences of

each characters in the string.

13. Develop a function to prompt the user for a string and a letter to be searched in the string and print the

number of times the letter is found in string

14. Explain the concept of string slice with example

15. Explain the following string methods:

a) len() b) in operator c) dir() d) help() e) startswith()

f) find() g) upper() h) lower() i) strip() j) rstrip() k) replace()

Page 5: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

9. Develop a program to compare a given two strings using string comparison operators.

10. What is format operator and explain the purpose of it with the help of suitable example.

11. Write a Python program to read a string with punctuations and print the same string without punctuations.

12 Take the following Python code that stores a string: str=’X-DSPAM-Confidence: 0.8475’. Use find and

string slicing to extract the position of the string after the colon character and then use the float function to

convert the extracted string into floating point number.

FILES

1. Write a program to generate Fibonacci series upto the given limit by the defining FIBONACCI(n) function

5M

2. Write a python code to accept the file name from the user 7M

i. Display the first n lines of the file

j. Find the frequency of the occurrence of the word accepted from the user in the file

3. How computational fault or errors are handled in python? Show the same with an example program to

copy all lines beginning with vowels from FROM.text file to VOWEL.text file retaining other lines.

8M

4. Write a Python program to read the file and count and print the lines that start with the word “From”.

Prompt the user for the file name. Also use try/except to handle bad file names. Explain format operator

with examples in Python.

5. Consider a line "From [email protected] Sat Jan 5 09:14:16 2008" in the file email.txt. Write

Pythonic code to read the file and extract email address from the lines starting from the word "From".

6. Define File. Explain read, write and open operation associated to a file with example.

7. Develop a Pythonic code to count number of lines in a file.

8. Develop a program to search a specified text in a file and print the particular line rstrip().

9. Discuss the usage of try and except while opening a file. Develop a program to prompt user for file name

and search for the specified text in that file.

10. Discuss the purpose of built-in function repr() while debugging.

Write a program to read through a file and print the contents of the file (line by line) all in upper case

MODULE 3

LIST

1. Describe any two list operations and list methods. Python program to accept n numbers from user find sum

of all even numbers and odd numbers entered in list 8M, Jan 2019

2. What are list? List are mutables, justify this statement with example 5M, Jul 2018

3. Implement a python program using list to store and display the average of n intergers accepted from the

user. 5M, Jul 2018

4. Consider the list qty=[5,4,7,3,6,2,1] and write a python code to perorm the following operation without

Page 6: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

using built-in methods: 8M, Jul 2018

a) Insert an element 9 at the beginning of the list b) Insert an element 8 at the end of the list c)

Insert an element 8 at the index position 3 of the list d)Delete an element at the end of the list e)

Delete an element at the beginning of the list f) Delete an element 8 at the index position 3 g) Print

the list reverse order h) Delete all the elements of the list

5. Explain join(), split() and append() methods in a List with examples. Write a program which repeatedly

reads numbers until the user enters ‘done’. Once ‘done’ is entered, print out the total, count, and average of

the numbers. If the user enters anything other than a number, detect their mistake using try and except and

print an error message and skip to the next number.

6. Give any four differences between a list and a string in Python.

7. What is a list of lists? Give an example along with its memory model.

8. Store the following data in a list, in a set and in a dictionary.

DICTIONARIES

1. List merits of dictionary over list. WAP the accept USn and marks obtained, find maximum, minimum

& student USN, who have scored in the range 100-85, 85-75, 75-60 and below 60 marks separately

8M, Jan 2019

2. Explain dictionary. Demonstrate with python program 5M, Jul 2018

3. Write Pythonic code to Count and Print the occurrence of each of the word in the file using

dictionaries. Prompt the user for the file name. Also use try/except to handle bad file names.

4. Consider the string ‘brontosaurus’. Write Pythonic code that implements and returns the functionality

of histogram using dictionaries for the given string. Also, write the function print_hist to print the keys

and their values in alphabetical order from the values returned by the histogram function.

5. Write Pythonic code to create a function called most_frequent that takes a string and prints the letters in

decreasing order of frequency. Use dictionaries.

6. Write Pythonic code to input information about 20 students as given below:

1) Roll number

2) Name

3) Total Marks

7. Get the input from the user for a student name. The program should display the Roll number and

total marks for the given student name. Also, find the average marks of all the students. Use

Page 7: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

dictionaries.

8. Write a Python program to read a string with punctuations and print the same string without

punctuations.

9. Write a Python program to read a word and print the number of letters, vowels and percentage of

vowels in the word using a dictionary.

TUPLES

1. Compare and construct tuples with list. Explain the following operations in tuples:

a. Sum of two tuples

b. Slicing operations

c. Comparision of two tuples

d. Assignments to variables 8M, Jan 2019

2. How tuples are created in python? Explain different ways of accessing and creating them.

5M, Jul 2018

3. Define Tuple. Explain DSU pattern. Differentiate between tuples and dictionaries?

4. Write Pythonic code to demonstrate tuples by sorting a list of words from longest to shortest using

loops.

5. Develop a Pythonic code to print 10 most common words and construct the list of (val,key) tuples and

then sort the list in reverse order.

6. How are dictionaries and tuples used together? Demonstrate the use of tuple assignment with

dictionaries to traverse the keys and values of dictionary.

7. Develop a Pythonic code Read and parse the “From” lines and pull out the addresses from the line.

Count the number of messages from each person using a dictionary. After all the data has been read,

print the person with the most commits by creating a list of (count, email) tuples from the dictionary.

Then sort the list in reverse order and print out the person who has the most commits.

8. This program counts the distribution of the hour of the day for each of the messages. You can pull the

hour from the “From” line by finding the time string and then splitting that string into parts using the

colon character. Once you have accumulated the counts for each hour, print out the counts, one per

line, sorted by hour.

9. Write a program that reads a file and prints the letters in decreasing order of frequency. Your program

should convert all the input to lower case and only count the letters a-z. Your program should not count

spaces, digits, punctuation, or anything other than the letters a-z. Find text samples from several

Page 8: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

different languages and see how letter frequency varies between languages.

REGULAR EXPRESSIONS

1. Explain extracting data using regular expressions. Implement a python program to find for lines having

‘@’ sign between characters in a read text file. 8M, Jan 2019

2. WAP to read all the lines in a file accepted from the user & print all email addresses contained in it.

Assume the email addresses contain only non-white space characters.

6M, Jul 2018

3. WAP to search for a line that starts with the word ‘From’ and a character followed by atwo digit number

between 00 and 99follwed by ’:’. Print the number if it is greater than zero. Assume any input file.

6M, Jul 2018

4. Why do you need regular expressions in Python? Consider a file “ait.txt”. Write a Python program to read

the file and look for lines of the form

X-DSPAM1-Confidence: 0.8475

X-DSPAM2-Probability: 0.458

Extract the number from each of the lines using a regular expression. Compute the average of the

numbers and print out the average. Also use try/except to handle bad file.

5. Why do you need regular expressions in Python? Consider a line "From [email protected]

Sat Jan 5 09:14:16 2008" in the file email.txt. Write Pythonic code to read the file and extract email

address from the lines starting from the word "From". Use regular expressions to match email address.

6. Explain regular expression module with their methods.

7. Write a program using regular expression

a. To match lines that start with string ‘From:’

b. To match lines that starts with ‘F’ followed by 2 characters, followed by ‘m:’

c. search for that start with ‘From:’ and have an at-sign.

8. Explain how strings can be extracted. Write Pythonic code to search for lines that have an at

sign between characters.

9. Write Pythonic code to search for lines that have an at sign between characters. The characters

must be a letter or number.

10. Write Pythonic code to Search for lines that start with 'X' followed by any non whitespace characters and ':'

followed by a space and any number. The number can include a decimal. Then print the number if it is

greater than zero.

11. Write Pythonic code to Search for lines that start with 'Details: rev=' followed by numbers and '.' Then print

the number if it is greater than zero.

12. Write a program to Search for lines that start with From and a character followed by a two digit number

Page 9: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

between 00 and 99 followed by ':' . Then print the number if it is greater than zero.

13. With example explain special characters and character sequences.

14. Write a simple program to simulate the operation of the grep command on Unix. Ask the user to enter a

regular expression and count the number of lines that matched the regular expression.

15. Write a program to look for lines of the form `New Revision: 39772` and extract the number from each of

the lines using a regular expression and the findall() method. Compute the average of the numbers and print

out the average.

MODULE 4

CLASSES AND OBJECTS

1. How class can be instantiated in Python. WAP to express instance as written value to define class

RECTANGLE with members weight, height, corner_x, corner_y and member function: to find centre

area and perimeter of rectangle. 8M, Jan 2019

2. Explain init and str method with an example python program 8M, Jan 2019

3. Define polymorphism. Demonstrate polymorphism with function and find histogram to count the

number of times each letter appears in word and sentence. 8M, Jan 2019

4. Write Pythonic code to create a function named move_rectangle that takes an object 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.

5. Consider a user defined class called Time that records the time of the day. Create a new Time object

and assign attributes for hours, minutes and seconds. Write a function called print_time that takes a

Time object and prints it in the form hour:minute:second. 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.

Write a function called increment which adds a given number of seconds to a Time object.

6. Write an object oriented Python program to create two time objects : Current _ time and Bread _ time

which contains bread baking time. Include addTime method to display the total time taken by the bread

maker to prepare a bread.

7. What are the steps that Python follows while creating an object?

CLASSES AND FUNCTION

8. What is a pure function? WAAP to find durations of event if start and end time is given by defining

Page 10: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

class TIME. 8M, Jan 2019

9. Using datetime module write a program that gets the current date and print the day of the week

4M, Jul 2018

10. Consider a user defined class called Point. Write a function called distance that takes two Points as

arguments and returns the distance between them.

11. Explain Pure functions and modifiers with example program.

12. Explain Prototyping versus planning.

13. Write a program that takes a birthday as input and prints the user’s age and the number of days, hours,

minutes and seconds until their next birthday. For two people born on different days, there is a day

when one is twice as old as the other. That’s their Double Day. Write a program that takes two

birthdays and computes their Double Day

CLASSES AND METHODS

1. Define polymorphism. Demonstrate polymorphism with function and find histogram to count the

number of times each letter appears in word and sentence. 8M, Jan 2019

2. What are polymorphism functions? Explain with a snippet code. 5M, Jul 2018

3. Create a student class and initialize it with name and roll number. Design methods to :

i. Display_to display all the information of the student.

ii. setAge_to assign age to student.

iii. setMarks_to assign marks to the students 7M, Jul 2018

4. What does the keyword self in python mean? Explain with an example. 5M, Jul 2018

5. Show using a python code how __init__ method is invoked when an object is initiated. Explain its

working. 6M, Jul 2018

6. Explain __str__ method with a python program. 5M, Jul 2018

7. Write an __init__ method for the Point class that takes x and y as optional parameters and assigns them

to the corresponding attributes. 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 x coordinate is

the sum of the x coordinates of the operands, and likewise for the y coordinates. 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.

8. What is Operator Overloading? Write Pythonic code to overload “+”, “-” and “*” operators by

Page 11: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

providing the methods __add__, __sub__ and __mul__.

9. Explain __str__ method with example program.

10. Explain type-based dispatch. Write a Pythonic code version of __add__ that checks the type of other

and invokes either add_time or increment.

Explain Polymorphism in Python in detail with examples.

MODULE 5

NETWORKED PROGRAMS

1. Consider a Photo directory with various Photos and a description for each Photo. The format would be

./2006/03/24-03-06_2018002.jpg

./2006/03/24-03-06_2018002.txt

Assume that over the years this Photo directory has accumulated bad text files that doesn’t contain a

description for the image. Write Pythonic code to clean up a Photo Directory by recognizing and

removing bad files.

2. Define socket. Write a Python socket program to prompt the user for the URL so it can read any web page.

You can use split(’/’) to break the URL into its component parts so you can extract the host name for the

socket connect call. Add error checking using try and except to handle the condition where the user enters

an improperly formatted or non-existent URL.

3. Define JSON. Construct a simple JSON document. Bring out the differences between XML and JSON.

Write Pythonic code to parse JSON document.

4. Develop a simple application in Python to prompt the user for a search string, call the Google geocoding

API, and extract information from the returned JSON.

5. Define socket. Write a Python program to retrieve an image over HTTP.

6. Write a Python program that makes a connection to a web server requesting for a document and display

what the server sends back. Your Python program should follow the rules of the HTTP protocol. List the

common headers which the webserver sends to describe the document.

USING WEB SERVICES

1. Write Pythonic code to retrieve a user’s Twitter friends, parse the returned JSON, and extract some of the

information about the friends.

2. State the need for urllib in Python. Explain why data is retrieved in blocks. Write Pythonic code to read

any sized binary file using urllib without using up all of the memory you have in your computer.

3. Give an example to construct a simple web page using HTML. State the need for BeautifulSoup library in

Python. Write Pythonic code to read a web page using urllib and then use BeautifulSoup library to extract

Page 12: EAST WEST INSTITUTE OF TECHNOLOGY13. A number with more than one digit is input through the keyboard. Write Pythonic code to reverse the digits in the number and find the sum of all

the href attributes from the anchor (a) tags.

4. Define XML. Construct a simple XML document and represent it with a diagram. Write Pythonic code to

loop through XML nodes in the document.

5. State the need for urllib in Python. Write Pythonic code to retrieve the file “ait.txt” by using the URL

http://dr-ait.org/code/ait.txt. Also compute the frequency of each of the word in the retrieved file.

6. Give an example to construct a simple web page using HTML. Write Pythonic code to match and extract

the various links found in a webpage using urllib.

USING DATABASES AND SQL

1. Define SQLite and create a database file and a table named Tracks with two columns in the database.

2. Discuss about Structured Query Language with any four commands.

3. Write a Pythonic code to create an application for Twitter spidering.

4. Explain the Constraints in database tables and write a syntax to

Retrieve and insert a record.

5. Explain the three kinds of keys used in a database model.

Write a Pythonic code the data that will have in the database after the multi-table Twitter spider program

(above) has been run several times