0% found this document useful (0 votes)
679 views7 pages

Python Imp Questions

This document contains 22 questions related to Python programming. The questions cover a range of Python topics including variables, data structures, functions, exceptions, file I/O, recursion, searching, and more. They include questions that ask about concepts, ask to write code to demonstrate concepts, and programming problems to solve.

Uploaded by

Abhishek Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
679 views7 pages

Python Imp Questions

This document contains 22 questions related to Python programming. The questions cover a range of Python topics including variables, data structures, functions, exceptions, file I/O, recursion, searching, and more. They include questions that ask about concepts, ask to write code to demonstrate concepts, and programming problems to solve.

Uploaded by

Abhishek Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 7

IMPORTANT QUESTIONS FOR

PYTHON
1. What are local variables and global variables in Python?
2. What is the difference between Python Arrays and lists?
3. Define ADTinterface.
4. Differentiate Fruitful functions and void functions.
5. 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?
6. Discuss ADT in python. How to define ADT? Write code for
student information.
7. Explain the iterator. Write a program to demonstrate the
tower of Hanoi using function.
8. What is Python? How Python is interpreted? What are the tools
that help to find bugs or perform static analysis? What are
Python decorators?
9. Write short notes with example: The Programming Cycle for
Python, Elements of Python.
10. How memory is managed in Python? Explain PEP 8.
11. Explain higher order function with respect to lambda
expression.
12. Explain Unpacking Sequences, Mutable Sequences,
and List Comprehension with example.
13. Discuss File I/O in python.
14. Describe the behavior of “range (s, e)”inPython.
15. Discuss Exceptions and Assertions in python.How to
handle Exceptions with Try-Finally? Explain 5 Built-in
Exceptions with example.
16. Discuss and differentiate Iterators & Recursion.
17. 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.
18. Describe the differences between a linear search and a binary
search?
19. Describe the difference between:
import library
And
from library import *
PROGRAMMING QUESTIONS

1. Write a Python Program for Sieve of Eratosthenes.


2. Write a for loop that prints numbers from 0 to 57, using range
function.
3. What is the purpose for else clause of a loop? Explain how else
works with while and for loops, with examples?
4. Explain about different types of arguments in Python.
5. Write a program for Recursive Fibonacci series.
6. Write a Python program to read a file line-by-line store it into a
variable.
7. Write a program to sort list of dictionaries by values in Python –
Using lambda function.
8. Write a Python program to convert time from 12 hour to 24-hour
format.
9. Write a Python Program for How to check if a given number is
Fibonacci number.
10. Write a Python program to print even length words in a string.
11.Consider the program:

x = ['12', 'hello', 456] x[0] *= 3

x[1][1] = 'bye'

Explain why this program generates an error.


12. Write a program to demonstrate the tower of Hanoi using
function.
13. Which of the following statements produce an error in
Python?
14. x, y, z = 1,2,3 # s1

a, b = 4,5,6 # s2

u = 7,8,9 # s3, (List all the statements that have error.)

20. What is the output of the following program? (lambda x,y : y -


2*x) (1, 11)
15. 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 returned. For
example,

removekth(“PYTHON”, 1) returns “PTHON”


removekth(“PYTHON”, 3) returns “PYTON”
removekth(“PYTHON”, 0) returns “YTHON”
removekth(“PYTHON”, 20) returns “PYTHON”

16. Write a Python function average to compute the average of a


list of numbers. The function must use try-except to handle the
case where the input list is empty. Further, in that case the
average for the empty list should be set to 0.0 using the except
block.
17. Write a function lessthan(lst, k) to return list of numbers less than
k from a list lst. The function must use list comprehension.
Example: lessthan([1, -2, 0, 5, -3], 0) returns [-2, -3]

18. 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]

19. Write a function makePairs that takes as input two lists of equal
length and returns a single list of same length where k-th element is
the pair of k-th elements from the input lists. For example,

makePairs([1,3,5,7],[2,4,6,8])

returns [(1,2),(3,4),(5,6),(7,8)]

makePairs([],[])

returns []

20. Show an example where both Keyword arguments and Default


arguments are used for the same function in a call. Show both the
definition of the function and its call.
19. Write a Python program, triangle(N), that prints a right triangle
having base and height consisting of N * symbols as shown in these
examples:

triangle(3) prints: *

**

***

triangle(5) prints: *

**

***

**** *****

20. Write a Python program, countSquares(N), that returns the count


of perfect squares less than or equal to N (N>1). For
example:countSquares(1) returns 1

# Only 1 is a perfect square <= 1 countSquares(5) returns 2

# 1, 4 are perfect squares <= 5 countSquares(55) returns 7

# 1, 4, 9, 16, 25, 36, 49 <= 55

21. Write a Python function, alternating(lst), that takes as argument a


sequence lst. The function returns True if the elements in lst are
alternately odd and even, starting with an even number. Otherwise it
returns False.
For example:

alternating([10, 9, 9, 6])returnsFalse
alternating([10, 15, 8])returnsTrue
alternating([10]) returns True
alternating([]) returns True
alternating([15, 10, 9])returnsFalse

22. Write a Python function, searchMany(s, x, k), that takes as


argument a sequence s and integers x, k (k>0).The function returns
True if there are atmost k occurrences of x in s.Otherwise it returns
False.
For example:

searchMany([10, 17, 15, 12], 15, 1)returns True

searchMany([10, 12, 12, 12], 12, 2)returns False

searchMany([10, 12, 15, 11], 17, 18)returnsTrue

You might also like