Python Unit-2 Previous Questions

SEMESTER END EXAMINATIONS – JUNE 2024

Write a Python function named average_list that takes a list of numbers as input and returns their average. Additionally, include a condition to ensure that the input is a list of numeric values only that are >=1). What is the output when this list average_list is: (i) An empty list (ii) a list containing non-numeric values (iii) -1 (iv) 10000000000000000000000000000

Implement a program that prompts the user to enter a tuple of integers. Calculate and print the sum of all integers in the tuple.

Explain the purpose of slicing in Python lists. Provide at least 4 examples to demonstrate slicing operations.


Design a Python program to create a dictionary containing the names and ages of five people. Determine the name of the oldest person in the dictionary.

Create a NumPy array of integers and perform the following operations: i) Calculate the shape of the array. ii) Print a subset of the array using slicing. iii) Multiply all elements of the array by 2 and print the result.


BACKLOG SUBJECT EXAMINATIONS – SEPTEMBER / OCTOBER 2023

Consider the list sub1={ANM,Py,DS,ASE,Java,OOPS } perform the following operations and show the output i) Insert the Sub AWP at the position 3 ii) Insert the DMS at the position 2 from the last. iii) Return the list from the index position 1 to 5 iv) Change the value of the Subject in the index 5 to BigData v) Check whether java is present in subj1 vi) Print the list in the reverse order vii) Delete the element at the index position 6 viii) Return the total elements in the list

Write a python program to count number of vowels and consonants, identify numbers, uppercase letters, lowercase letters and special characters in a given string.

Discuss the significance of dictionary. Develop a python program to simulate language dictionary.


Discuss the following with an example: i) Indexing ii) Splitting arrays iii) Shape and reshape.

Illustrate 2-D and 3-D array iterating with respect to numpy.


SEMESTER END EXAMINATIONS – MAY / JUNE 2023

Develop a python program for the following: Create a dictionary by asking the user to give the name and marks of 10 different students. Sort the dictionary created according to marks.

Develop a python program to print unique elements in a list.


Predict the output of the following and justify your answer:

i) 
>>>lst=[1,7,3,9,2]
>>>lst.append([4,5])
>>>lst.extend([9,3])
>>>lst.pop(3)
>>>lst.insert(3,6)


ii) 
>>>22 > "z"
>>>[1, 2] in [0, 1, 2, 3]
>>>str=“Python programming”
>>>print(str[7:-4])
>>> ls=[34, 'hi', -5]
>>> ls.sort()

Explain the use of join() and split() string methods with examples. What does it mean strings are immutable? Explain with an example.


Write a program to create NumPy array and get the smallest and largest element from the array and display them.

Explain the following routines of NumPy with examples: i) reshape ii) resize iii) unique iv) append v) insert.


SUPPLEMENTARY SEMESTER EXAMINATIONS – SEPTEMBER 2022

Assume that the name t is assigned a value ‘Programming with Python’ what will be the output when we execute the following commands and explain.

t[13:], t[:9], t[:], t[7:16], t[5:-10], t[6:-6:], t[-2::-1], t[::-2],
t[-2:1:-2], t[:-8]

How do you demonstrate that lists are equal and identical?

Use the for loop and give example for: i) Processing characters in Strings ii) Displaying values and keys of a dictionary iii) Looping over List of Lists.


SUPPLEMENTARY SEMESTER EXAMINATIONS - NOVEMBER 2022

List and describe any five methods on tuples.

How do you create and access dictionaries in Python? Explain the operations len(), copy(), clear(), items() on dictionaries.

Demonstrate slicing on strings. Also explain the use of join() and split() string methods with examples.


SEMESTER END EXAMINATIONS – JUNE 2022

Differentiate between lists and tuples in Python. How to create nested lists? Demonstrate how to create and print a 3-dimensional matrix with lists.

Develop a Python program that counts the number of occurrences of a letter in a string, using dictionaries.


Develop a Python code to extract the Even elements indices from the given list.

Develop Python script that takes a list of words and returns the length of the longest one using tuples.


EXAMINATIONS SEPTEMBER /OCTOBER 2021 SUPPLEMENTARY

Explain the usage of the following methods with examples: i) extend() ii) pop() iii) sort() iv) split() v) join()

Explain what ord() and chr() function is used for. Using the same, Write a function that takes a string input and converts all uppercase letters to lowercase and vice versa Sample input: I love PyTHon Sample output: i LOVE pYthON


Demonstrate how dictionaries are created and used in Python. List and describe any five methods on dictionaries.

Develop a python program to count the frequency of words in a string using dictionary.


EXAMINATIONS SEPTEMBER /OCTOBER 2021 SUPPLEMENTARY

Demonstrate any five list functions with the help of an example.

Demonstrate the usage of update( ) function to update one dictionary with another dictionary.


Assume that the name a is assigned a value ‘mca@rit’ what will be the output when we execute the following commands and explain.

a[5:], t[:4], t[2:-2:2], t[3:4], t[2:-2], t[1:-2:], t[-3::-2], t[::-4],
t[-4:1:-4], t[:-3]

Develop a script for filtering odd and even numbers into two separate lists from a list of numbers.


EXAMINATIONS SEPTEMBER /OCTOBER 2020 SUPPLEMENTARY

List and describe any five functions to operate Tuples.

Explain the use of join() and split() string methods with examples. What does it mean strings are immutable? Explain with an example.

Demonstrate the creation and operation of dictionaries in Python.


When you use the + operator to concatenate two lists, does it make a copy or a reference of the arguments? Explain with the help of an example.


SEMESTER END EXAMINATIONS – JUNE 2019

The third person singular verb form in English is distinguished by the suffix -s, which is added to the stem of the infinitive form: run -> runs. A simple set of rules can be given as follows:

  • If the verb ends in y, remove it and add ies
  • If the verb ends in o, ch, s, sh, x or z, add es
  • By default just add s Develop a Python Script for the rules above

Exemplify built – in list methods


Develop Python script that takes a list of words and returns the length of the longest one using tuples.

List and exemplify the built – in dictionary methods.


SUPPLEMENTARY SEMESTER EXAMINATIONS – JULY 2019

predict the output of the following and justify your answer

i) 
22<"A"

ii) 
i = 5
print("welcome") if i>5 else print("bye")

iii)
[1,2] in [0,1,2,3]

iv)
s = "programming"
print(str[5:-2])

v)
ls = [34,'hi',-5]
ls.sort()

What do you mean by mutable and immutable data structures? Explain with examples.

Predict the output of the following and justify your answer:

i) 
a = -45
print (--a)

ii)
str1 = ‘hello’
print(str1[-1:])

iii)
a=[1,2,3,4,5,6,7,8,9]
a[::2]=10,30,50,50,90

iv)
a, b, c = True, False, False
if a or b and c:
	print "MSRIT"
else:
	print "RNSIT"

What is a string? Discuss the different ways of representing a string in Python.


MAKEUP EXAMINATIONS – JULY 2019

Explain the usage any 5 list operating methods with examples.

Implement a telephone directory using Dictionaries.


How do you create and access dictionaries in Python? List and describe any 5 methods on dictionaries.

Develop a python program to find whether the given string is palindrome or not.


SEMESTER END EXAMINATIONS – MAY/JUNE 2018

Write the evaluation result of the following expressions:

i) not “True”
ii) – 22 % 5
iii) “99” + 1
iv) dir(“python”) v) ['H', 'He', 'Li'] + 'Be'

Store the following data in a list, a tuple, and a dictionary:

India 91
USA   1
UK    41
Japan 9

Consider the list scores = [5, 4, 7, 3, 6, 2, 1] and write the python instruction to perform the following operations: i) Insert an element 9 at the beginning of the list. ii) Insert an element 8 at the index position 3 of the list. iii) Delete an element at the end of the list. iv) Delete an element at the index position 3.

Predict the output of the following and justify your answer:

i)
S="Vishweswaraiah"
print(s[4:])
print(s[:5])

ii)
str1 = "Bangalore"
str1[1] = "e"
str1[6] = str1[8] = "u"
print(str1)

iii)
a = -45
print(--a)

iv) a, b, c = True, False, False
if a or b and c:
	print "MSRIT"
else:
	print "RNSIT"

SUPPLEMENTARY SEMESTER EXAMINATIONS – JULY/AUGUST 2018

Demonstrate any four functions of lists with the help of an examples.

Demonstrate any three functions of dictionaries in python with examples.


SEMESTER END EXAMINATIONS – MAY/JUNE 2017

Explain the usage of the following methods with examples: (i) extend() (ii) pop() (iii) sort() (iv) split() (v) join()


How do you create and access dictionaries in Python? Explain the operations len(), copy(), clear(), items() on dictionaries.

Develop a python program to count the frequency of word in a string using dictionary.

Develop a python program to print unique elements in a list.