Question_Bank PUT BCC 302 Python Prog
Question_Bank PUT BCC 302 Python Prog
Short Answer:
Explain features of any two Python IDLE‟s.
Difference between / and // operator in python with an example.
Give difference between = = and is operator in python
In some languages every statements end with semicolon (;).What happen if you put semicolon(;)
at the end of a Python statements.?
Which of the following statements produce an error in Python?
x, y, z = 1,2,3 # s1
a, b = 4,5,6 # s2
u = 7,8,9 # s3
List all the statements that have an error
What will be the output of the following code?:
str1=‟Hello World!‟
n=len(str1)
str2=”World! hello”
str2[1]=‟a‟
print(str1[-n])
print(str1*3)
print(str2[1])
What is the output of the following program?
list= [lambda arg=x : arg * 10 for x in range(1, 5)]
for i in list:
print(i ( ))
Compare find( ) and count( ) function in string. Explain it with example.
Explain nested if ,else statement with example.
Differentiate between Fruitful function and Void function.
What does the readline ( ) function return when it reaches the end of the file?
Which function is used to create identity matrix in NumPy?
Describe about different functions of matplotlib and pandas
Draw the flow chart of while and for loop ,by explaining their control flow.
Write a recursive Python function “rprint” to print all elements in a list in reverse.
rprint([]) prints nothing
rprint([1,2,3]) prints 3 2 1
Unit I & II
Discuss why python is interpreted language ?Explain history and features of python
Discuss why Python is called as dynamic and strongly typed language?
Write short notes on
i.) Indentation in python
ii.) Type conversion in python
What is python ? How python is interpreted language.
What do you mean by flow of control in python. How selection is implemented in python
Describe the behavior of “range ([start],stop[ ,step])” in Python.
Describe the various iteration statements in python by giving flow chart and explain with suitable
example.
Explain the purpose and working of loop. Discuss break and continue with example. Write a
program to convert time from 12 hour to 24- hour format.
Explain Unpacking Sequence, Mutable Sequences ,and List Comprehension with example.
Write a program to short list of dictionaries by values in python by using lambda function.
Develop a python program to make a calculator and perform the basic five arithmetic
operations based on the user input.The menu should be continuously available to the user.
Develop a python program to find largest and smallest number in a list of numbers.
List=[12,45,22,1,2,41,31,10,8,6,4]
Write a Python function, searchMany(s, x, k), that takes as argument a sequence s and
integers x, k (k>0). The function returns True if there are at most k occurrences of x in s.
Otherwise it returns False. For example:
searchMany([10, 17, 15, 12], 15, 1) returns True
searchMany([10, 12, 12, 12], 12, 2) returns False
searchMany([10, 12, 15, 11], 17, 18) returns True
Illustrate different list slicing constructs for the following operations on the following list:
L=[10,20,30,40,50,60,70,80,90]
a) Returns a list of numbers starting from the last to second items of the list.
b) Returns a list of numbers starting from 3rd item to second last item.
c) Return a list of numbers that has only even position of List L to List M .
d) Return a list of numbers that starts from middle of the list.
e) Return a list that reverses all the elements starts from 0 to middle index only and return
the entire list
Write a program with user defined function with string as a parameter which replaces all
vowels in the string with „&‟.
Explain the following string functions on given string: str= ”Hello World hello world”
a) split( ) b) title ( ) c) sort ( ) d) replace ( ) e) partition () by writing the codes of each one .
Illustrate different string slicing construct for the following operations on the string:
Str1=”Welcome to Sms!”
a) Returns a string that gives 7th character from last upto 1st character.
b) Return a string that is too big is truncated down to the end of string.
c) Returns a string ,if 1st index is not mentioned and slice start from 0 to 4 index.
d) Return a string if 1st index (start value )is > 2nd index(stop value).
e) Return string ,Str1 in reverse order.
f) Return character of string ,str1 at index -6,-5,-4,-3 and -2 are sliced.
Write a program using a user defined function to check if a string is a palindrome or not.
( A string is called a palindrome if it reads same backwards as forwards. For example KANAK is
a palindrome.)
What do mean by a function in python .How many types of functions are? Explain in detail.
Write Python program to swap two numbers without using Intermediate/Temporary
variables. Prompt the user for input.
Write a program that accepts a sentence and calculate the number of digits,uppercase and
lowercase letters.
Write python code snippet to display n terms of Fibonacci series.
Explain Expression Evaluation and Float Representation.Write a python program how to check if a
given number is Fibonacci number.
Unit-III
Python Complex Data Types
What do mean by a function in python .How many types of functions are? Explain in detail.
Explain how list is mutable data type? Write a program to remove duplicates items of
list,list1=[10,20,10,30,20,40,30,50] using list native or list comprehension method and print
fresh list (having no duplicates
Write a user defined function to check if a number is present in the list (list should be
inputted by user) or not. If the number is present ,return the position of the number? Print an
appropriate message if the number is not present in the list.
Explain the concept of a set in Python and its characteristics. How elements are access, added
and removed from a set, explain by giving an example?
What is dictionary? How elements are access in a dictionary? Write a python program to find
the sum of all items in a dictionary. For example if d={„A‟:100,‟B‟:540,‟C:239‟} then output
should be 879.
Compare list and tuple data structure with suitable example.Explain the concept of list
comprehension.
Write a Python function removekth(s, k) that takes as input a string s and an integer k>=0
and removes the character at index k. If kis beyond the length of s, the whole of s is returned.
For example,
removekth(“PYTHON”, 1) returns “PTHON”
removekth(“PYTHON”, 3) returns “PYTON”
removekth(“PYTHON”, 0) returns “YTHON”
removekth(“PYTHON”, 20) returns “PYTHON”
Write a program factors(N) that returns a list of all positive divisors of N (N>=1). For
example:
factors(6) returns [1,2,3,6]
factors(1) returns [1]
factors(13) returns [1,13]
Write a function makePairs that takes as input two lists of equal length and returns a single
list of same length where k-th element is the pair of k-th elements from the input lists. For
example,
makePairs([1,3,5,7],[2,4,6,8])
returns [(1,2),(3,4),(5,6),(7,8)]
makePairs([],[])
returns []
Show an example where both Keyword arguments and Default arguments are used for the
same function in a call. Show both the definition of the function and its call.
Write a Python program, countSquares(N), that returns the count of perfect squares
less than or equal to N (N>1). For example:
countSquares(1) returns 1
# Only 1 is a perfect square <= 1
countSquares(5) return 2
# 1, 4 are perfect squares <= 5
countSquares(55) returns 7
# 1, 4, 9, 16, 25, 36, 49 <= 55
Construct a program that accepts comma separated sequences of words as input and print
the words in the comma separated sequences after sorted them alphabetically.
Suppose the following input is supplied to program:
Hello, Bag ,Welcome ,World
The output should be:
Bag,Hello,Welcome,World
What do you mean by recursion? Write a recursive function to compute the factorial of an
input number N.
Write a Python function, alternating(lst), that takes asargument a sequence lst. The function
returns True if the elements in lst are alternately odd and even, starting with an even
number.Otherwise it returns False. For example:
alternating([10, 9, 9, 6]) returns False
alternating([10, 15, 8]) returns True
alternating([10]) returns True
alternating([]) returns True
alternating([15,10, 9]) returns False
Unit-IV
Python File Operations
1. Discuss the concept of iterators in python. Explain, how we can create text file in python?
Discuss the python program to write the number of letters and digits in given input string into
file object.
2. There is a file named Input.Txt. Enter some positive numbers into the file named Input.Txt.
Read the contents of the file and if it is an odd number write it to ODD.TXT and if the number is
even, write it to EVEN.TXT
3. Discuss file I/O in Python. How to perform open,read, write and close into a file ? Write
a python program to read a file line- by- line store it into a variable.
4. Construct a program to change the contents of file by reversing each character separated by
commas:
Welcome!!
Output:
W,e,l,c,o,m,e,!,!
5. Write a python program to find the longest word in a file.Get the file name from user
6. Write a python program to count the total numbers of upper case letters,lower case letters and
digits used in the text file “forest.txt”.
7. Write a python to count the occurrences of each word and also count the total number of
words in the file.(Assume the file used is forest.txt)
8. Write a python program to reverse each word in a file (Assume the file used is forest.txt )
9. Write a program to replace all spaces from text with – (dash) and save to a new file.
10. Write a program to replace multiple spaces and new line with single spaces in a text file.