python July 2015
python July 2015
2. a) Using Python, Implement a simple calculator for any six Arithmetic operators by taking 8
operands and operators from the user.
b) Explain the following with an example for each. 8
i. in (2
ii. ord() each)
ii. chr()
iv. range()
c) Find the error/s in the below code 4
Num=input("Enter the number) (1 each)
if Num>0
print "Positive"
elsE:
pritn "Negative"
4. a) What is recursion? Write a python program to find the sum of digits of a given number using 8
recursion.
b) Which are the two ways in which you can import modules to the current Program? Explain 6
with an example for each.
c) List any three functions which support functional programming. 3
d) Given s=[1,6,9,6,3,4] ,Write the list comprehension for the following. 3
A) Create an unconditional list with same elements as 's'
B) Create a list with only elements which are greater than 3 in the given list 's'
C) Create a list with only elements which are even in the given list 's'
5 a) Which method is used to open the file using python language? Write the code to open a file 8
myfile.txt and write 'python' and `jython' in different lines. Add the code to open this file in
read mode and print the contents of the file line by line on the terminal. Then close the
opened file without fail.
b) Briefly explain the fundamental features of Object Oriented Programming with an example 6
of class.
c) What is an exception? Which is the root of all exception types? Also list the constructs used 6
in Exception handling.