Sixth Semester B.
Tech Degree Examination
(2018 Scheme)
18.605 Introduction to Python (T)
Time : 3 Hours Max. Marks : 100
PART – A
Answer all questions. Each question carries 2 marks
1. What do you mean by chained conditionals in python?
2. Write a python program to accept three numbers a,b and c. Find a + b and if the sum is
greater that c, display a2+b2. Otherwise display -1
3. Let x = 2**8+8/2/2 be an expression in python. What will be the value of x?
4. for i in range (50):
print(i)
convert the above code to its equivalent while loop.
5. Write a function to find the sum of all numbers between an input lower limit and an upper
limit.
6. let str = ‘python is a popular programming language’ be a string. What will be the output
of the following expressions?
(i) str[0:6] (ii) str[10] (iii) str[-4] (iv) str[-8:]
7. Compare tuple and list on the basis of mutability. Give example to illustrate this.
8. What is pickling? Mention any one usage of pickling.
9. Differentiate Class and Object.
10. Define a class to represent a rectangle which contains a method to calculate the area.
PART – B
Answer one full question from each module. Each question carries 20 marks
Module 1
11. a) What is meant by a statement? How can you construct a statement from variables and
expressions in Python? (10 marks)
b) Comment on the advantages of Python over other programming languages (10 marks)
12. a) with proper examples explain the rules associated with creating variable names in
Python. How does a variable name differ from keywords? (10 marks)
b) Describe various operators in Python. What is meant by order of operations? (10
marks)
Module 2
13. a) Write a python program to calculate nCr. Use a recursive function fact() to find the
factorial of a number.[nCr=n!/(r! * (n-r)!)] (10 marks)
b) ) Using “for”, write a Python program to print the multiplication table of all n’s where,
2<=n<=10. (10 marks)
14. a) Explain the advantages of functions? Write a menu driven python program to find the
area of a rectangle, square and a triangle. Use separate functions to calculate areas (10 marks)
b) Write a Python function to compute the power of a number. Use the function to
2 4 6
x x x
compute the sum of the series (1− + − +… n terms ) (10 marks)
2 4 6
Module 3
15. a) Write a Python program to check whether the input string is palindrome or not without
reversing the string. (10 marks)
b) Explain the concept of Dictionary data type in python. Create a sample Dictionary with
at least 5 operations. (10 marks)
16. a) What is meant by a tuple in Python? How does a tuple differ from Dictionary? (10
marks)
b) Write a python program to count number of occurrences of each character in an input
string, display the same. Display the most frequent character in the list separately. (10 marks)
Module 4
17. a) Explain the concepts of classes, attributes and methods in Python, with suitable
examples. (10 marks)
b) With suitable examples explain how the exceptions are handled in Python. (10 marks)
18. a) Define a class in Python to store the details of a train (name, source, destination),
with the following methods:
i) get_train_details() - to assign values to class attributes
ii) print_train_details( ) - to display the attribute values
Create an object of the class and invoke the methods. (10 marks)
b) Write a Python code to read a text file, and copy the contents to another file after
removing all the palindrome strings from it. (10 marks)
*****