NOTE!
Click on MENU to Browse between Subjects...17CS664 - PYTHON APPLICATION PROGRAMMING
Answer Script for Module 3
Solved Previous Year Question Paper
CBCS SCHEME
PYTHON APPLICATION PROGRAMMING
[As per Choice Based Credit System (CBCS) scheme]
(Effective from the academic year 2017 - 2018)
SEMESTER - VI
Subject Code 17CS664
IA Marks 40
Number of Lecture Hours/Week 3
Exam Marks 60
These Questions are being framed for helping the students in the "FINAL Exams" Only
(Remember for Internals the Question Paper is set by your respective teachers).
Questions may be repeated, just to show students how VTU can frame Questions.
- ADMIN
ANSWER :
i. Sum of two tuples
Answer:

Fig 15.1 Sum of two tuples

Fig 15.2 Output of Sum of two Tuples
ii. Slicing operators:
Answer:
Refer 18th
Question & Answer or Click Here
iii. Compression of two tuples:
Refer 2nd
Question & Answer or Click Here
iv. Assignments to variables.
Answer:

Fig 15.3 Assignment to variable

Fig 15.4 Output of Assignment to variable
ANSWER :
Refer 3rd
Question & Answer or Click Here
ANSWER :
17.1 Lists:
Refer 1st
Question & Answer or Click Here
17.2 Lists are mutable:
The elements in the list can be accessed using a numeric index within square-brackets. It is similar to extracting characters in a string.
>>> ls=[34, 'hi', [2,3],-5]
>>> print(ls[1])
hi
>>>print(ls[2]) [2, 3]
Observe here that, the inner list is treated as a single element by outer list. If we would like to access the elements within inner list, we need to use double-indexing as shown below -
>>> print(ls[2][0])
2
>>> print(ls[2][1])
3
Note that, the indexing for inner-list again starts from 0. Thus, when we are using doubleindexing, the first index indicates position of inner list inside outer list, and the second index means the position particular value within inner list.
Unlike strings, lists are mutable. That is, using indexing, we can modify any value within list. In the following example, the 3rd element (i.e. index is 2) is being modified
>>> ls=[34, 'hi', [2,3],-5]
>>> ls[2]='Hello'
>>> print(ls)
[34, 'hi', 'Hello', -5]
The list can be thought of as a relationship between indices and elements.
This relationship is called as a mapping
. That
is, each index maps to one of the elements in a list.
ANSWER :
18.1 Tuples:
A tuple
is a sequence of items, similar to lists. The
values stored in the tuple can be of any type and they are indexed using
integers. Unlike lists, tuples are immutable. That is, values within tuples
cannot be modified/reassigned. Tuples are comparable and hashable objects. Hence, they can be made as keys in dictionaries.
18.2 Creating a Tuples:
18.2.1 Without using Parentheses
Refer Fig 18.1
18.2.2 Using Parentheses
Refer Fig 18.1
NOTE: You can't create a single value in the tuples using 18.2.1 &
18.2.1 which is over come in 18.2.3
18.2.3 Using Function tuple()
Refer Fig 18.1
18.2.4 Using a one or More Existing Tuple (& Slicing them) to
Create a New Tuple:
Refer Fig 18.1

Fig 18.1 Various ways in Creating a Tuple

Fig 18.2 Output of various ways in Creating a Tuple
18.3 Various ways in accessing the Tuples:
(as same as strings)
18.3.1 Accessing Entire tuple values using tuple name:
Refer Fig 18.3
18.3.2 Accessing tuple using index value:
Refer Fig 18.3
18.3.3 Accessing tuples using slicing:
Refer Fig 18.3

Fig 18.3 Various ways in accessing the Tuples

Fig 18.4 Output of various ways in accessing the Tuples
ANSWER :

Fig 19.1 illustration of RE of a Mail Address

Fig 19.2 Output of RE of a Mail Address
Below Page NAVIGATION Links are Provided...
All the Questions on Question Bank Is SOLVED