0% found this document useful (0 votes)
3 views

Python Important Copy

Uploaded by

dss745147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Important Copy

Uploaded by

dss745147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1

Python Previously asked question


Short Questions
1. In some languages, every statement ends with a semi-colon (;). What happens if you put a semi-colon at
the end of a Python statement? [2019-20]
2. Mention five benefits of using Python. [2019-20]
3. How is Python an interpreted language? [2019-20]
4. What type of language is python? [2019-20]
5. What are local variables and global variables in Python? [2019-20]
6. Define floor division with example. [2019-20]
7. 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, 3 #S3 [2020-2021]
8. What is the role of precedence with example. [2020-2021]
9. How do you read an input from a user in python to be used as an integer in the rest of the program
?explain with an example. [2020-2021]
10. Explain the Programming Cycle for Python in detail. [2021-2022]
11. Describe the behaviour of “range (s,e)” in python. [2020-2021]
12. What will be the output of following python code?
While i<=3:
Print(i)
i+= 1
else:
print(0) [2021-22]
13. What is the difference between list and tuples in Python? [2019-20]
14. What is the difference between Python Arrays and lists? [ 2019-20][2022-23]
15. Differentiate Fruitful functions and void functions. [ 2019-20]
16. Write a recursive python function “rprint” to print all elements in a list reverse .
Rprint([]) prints nothing
Rprint([1,2,3]) prints 3,2,1 [2020-2021]
17. Consider the program :
X = [’12 ’, ‘hello’, 456]
X[0] *= 3
X[1][1] = ‘bye’
Explain why this program generates an error. [2020-2021]
18. What is the output of the following program ?
(lambda x,y : y – 2*x) (1,11) [2020-2021]
19. What will be the output of following python code? [2021-22]
Def cube(X):
return X*X*X
Prepared By:- Shubhi Verma Assistant Prof. SRGC
2

x= cube(3)
print(x) [2021-22]
20. Describe the concept of List Slicing with a suitable example. [2022-23]
21. Show the way to import the module in python. [2022-23]
22. What will be the output of the following python code
def count1(s):
vowels = "AEIOUaeiou"
count = 0
for c in s:
if c in vowels:
count += 1
return count
print(count1(‘I love India’)) [2022-23]
23. What will be the output of the following code?
list1 = ['M', 'o', 'n', 'k', 'y']
print("@".join(list1)) [2022-23]
24. Describe the use of class `__init__()` method. [2022-2023]
25. Explain the output of following function.
def printalpha (abc_list, num_list):
for char in abc_list:
for num in num_list:
print(char, num)
return
printalpha (['a', 'b', 'c'], [1, 2, 3]) [2022-2023]

26. Describe the concept of List Comprehension with a suitable example. [2023-2024]
27. Compute the output of the following python code:
def count(s):
for str in string.split():
s=”&”.join(str)
return s
print(count(“Python is fun to learn”)) [2023-2024]
28. How to use the function defined in library.py in main.py [2023-2024]
29. Describe the difference between linespace and argspace. [2023-2024]
30. Explain why program generates an error
X=[‘12’,’hello’,456]
X[0]*=3
X[1][1]=’bye’ [2023-2024]
31. Describe about different function of matplotlib and pandas. [2023-2024]

Prepared By:- Shubhi Verma Assistant Prof. SRGC


3

Long questions
1. What is Python? How Python is interpreted? What are the tools that help to find bugs or perform static
analysis? What are Python decorators? [ 2019-20] [2021-22]
2. Write short notes with example: The Programming Cycle for Python, Elements of Python, Type
Conversion in Python, Operator Precedence, and Boolean Expression. [2019-20]
3. How memory is managed in Python? Explain PEP 8. Write a Python program to print even length words
in a string. [ 2019-20]
4. What do you mean by Python IDE? Explain in detail. [2021-22]
5. Explain all the Conditional statement in Python using small code example. [ 2019-20]
6. Explain Expression Evaluation & Float Representation with example. Write a Python Program for How
to check if a given number is Fibonacci number. [ 2019-20] [2021-22]
7. Explain the purpose and working of loops. Discuss Break and continue with example. Write a Python
program to convert time from 12 hour to 24-hour format. [2019-20]
8. Write a python program to construct following pattern
*
**
***
****
*****
****
***
**
* [2021-22]
9. Discuss function in python with its parts and scope. Explain with example. (Take Simple calculator with
add, subtract, Division and Multiplication). [ 2019-20]
10. Explain higher order function with respect to lambda expression. Write a Python code to Count
occurrences of an element in a list. [ 2019-20]
11. Explain Unpacking Sequences, Mutable Sequences, and List Comprehension with example. Write a
program to sort list of dictionaries by values in Python – Using lambda function. [19-20][21-22][23-24]
12. 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 k is beyond the length of S, the whole of S is retuned. For example.
removekth("PYTHON",1) returns "PTHON"
removekth("PYTHON", 3)returns "PYTON"
removekth("PYTHON", 0) returns "PYTHON"
removekth("PYTHON", 20) returns "PYTHON" [2020-2021]
13. Write a function less than(1st, k) to return list of numbers less 10 than k from a list 1st. The function must
List comprehension. Example:
lessthan ([1, 2, 0, 5, -31, returns [-2, -3] [2020-2021]
14. 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] [2020-2021]
15. Write a Python program to change a given string to a new string where the first and last chars have been
exchanged [2021-22]
16. Write a Python program to add an item in a tuple. [2021-22]
Prepared By:- Shubhi Verma Assistant Prof. SRGC
4

17. 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. [ 2019-20]
18. Discuss Exceptions and Assertions in python. How to handle Exceptions with Try-Finally? Explain 5
Built-in Exceptions with example. [ 2019-20] [21-22]
19. Write a Python function average to compute the average of a list of numbers. [2020-2021]
20. How can you create python file that can be imported as a library as well as run as a standalone script?
[2020-2021]
21. Describe the difference between
Import library
And
From library import *
When used in python program . here library is some python library [2020-2021]
22. How can you randomize the items of a list in place in Python? [2021-22]
23. How to create and import a module in Python? [2021-22]
24. Explain the algorithm Programming Sieve of Eratosthene used in Python programming [2021-22]
25. Demonstrate five different built in functions used in the string. Write a program to check whether a
string is a palindrome or not. [2022-2023]
26. Develop a program to calculate the reverse of any entered number. [2022-2023]
27. Explain the list Comprehension with any suitable example. [2022-2023]
28. Explain the lambda function. How it is helpful in the higher order function. Explain map() function
with a suitable example. [2022-2023]
29. Discuss the different types of argument-passing methods in python. Explain the variable length
argument with any suitable example. [2022-2023]
30. Demonstrate the file handling procedure in detail. Write a python code to create a file with ‘P.txt’ name
and write your name and father’s name in this file and then read this file to print it [2022-2023]
31. Discuss various categories of operators in python. Find and explain stepwise solution of following
expressions if a=3, b=5, c=10.
i) a &b<<2//5**2+c^b
ii) b>>a**2<<2 >> b**2^c**3 [2022-2023]
32. Explain history and features of python while comparing python version 2 and 3. [2022-2023]
33. Write a program that accepts sequence of lines as input and prints the lines after making all characters
in the sentence capitalized.
e.g. If Input:
Hello world
Practice makes perfect
Then, Output:
HELLO WORLD
PRACTICE MAKES PERFECT
34. Illustrate different list slicing construct for the following operation on the following list:
L=[1,2,3,4,5,6,7,8,9]
1. Return a list of numbers starting from the last to second item of the list.
2. Return a list that start from 3rd item to second last item.
3. Return a list that has only even position elements of list L to List M.
4. Return a list that starts from the middle of list L.
5. Return a list that reverses all the elements starting from element at indexed 0 to middle index only
and return the entire list.
6. Divide the each element of the list by 2 and replace it with the remainder. [2023-2024]
Prepared By:- Shubhi Verma Assistant Prof. SRGC
5

35. Construct a function perfect_square(number) that return a number if it is a perfect square otherwise it
returns -1.
For example:
perfect_square(1) returns 1
perfect_square(2) returns -1 [2023-2024]
36. Contruct a program to change the contents of the file by reversing each character separated by comma:
Hello!!
Output
H,e,l,l,o,!,! [2023-2024]
37. Construct a plot for following dataset using matplotlib:

Food Calories Potassium Fat

Meat 250 40 8

Banana 130 55 5

Avocados 140 20 3

Sweet 120 30 6
Potatoes
Spinach 20 40 1

Watermelon 20 32 1.5

Coconut water 10 10 0

Beans 50 26 2

Legumes 40 25 15

Tomato 19 20 2.5
[2023-2024]

38. Determine a python function removenth(s,n) that takes an input a string and an integer n>= 0 and
removes a character at index n. if n is beyond the length of s then whole s is returned.
For example
removenth(“MANGO”,1) return MNGO
removenth(“MANGO”,3) return MANO [2023-2024]
39. Construct a program that accepts a comma separated sequence of words as input and prints the words in
a comma-seperated sequence after sorting them alphabetically.
Suppose the following input is supplied to the program :
without, hello, bag, world
Output:
bag, hello, without, world [2023-2024]

Prepared By:- Shubhi Verma Assistant Prof. SRGC


6

40. A website requires the users to input username and password t I password to register. Construct a
program to check the validity of password input by users.
Following are the criteria for checking the password:
1. At least 1 letter between [a-2]
2. At least 1 number between [0-9]
3. At least I letter between [A-Z]
4. At least 1 character from [$#@]
5. Minimum length of transaction password: 6
6. Maximum length of transaction password: 12
Your program should accept a sequence of comma separated passwords and will check them according
to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma.
[2023-24]
41. Construct a function ret smaller(1) that returns smallest list from a nested list. If two lists have same
length then return the first list that is encountered. For example:
ret smaller([[-2, -1, 0, 0.12, 1, 2], [3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]) returns [3,4,5]
ret smaller([[-2,-1,0,0.12, 1, 2], ['a', 'b', 'c', 'd', 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]]) returns [6, 7,
8, 9, 10] [2023-2024]
42. Construct following filters:
1. Filter all the numbers
2. Filter all the strings starting with a vowel
3. Filter all the strings that contains any of the following noun: Agra, Ramesh, Tomato, Patna.
Create a program that implements these filters to clean the text. [2023-2024]
43. Change all the numbers in the file to text. Construct a program for the same.
Example:
Given 2 integer numbers, return their product only if the product is equal to or lower than 10.
And the result should be:
Given two integer numbers, return their product only if the product is equal to or lower than one zero
[2023-2024]
44. Construct a program which accepts a sequence of words separated by whitespace as file input. Print the
words composed of digits only. [2023-2024]
45. Construct a program to read cities.csv dataset, remove last column and save it in an array. Save the last
column to another array. Plot the first two columns [2023-2024]
46. Design a GUI based Calculator which includes functionality addition, subtraction, Multiplication,
division and clear. Using tkinter.

Prepared By:- Shubhi Verma Assistant Prof. SRGC

You might also like