PYTHON PROGRAMMING PYQ
[Link] is indentation?
Q2. Write code to print the elements of the list 11 = [10, 20, 30, 40, 50].
Q3. What is a slice operator?
Q4. What is variable-length argument?
Q5. How to add multiple elements at the end of the list?
Q6. Explain the remove () method.
Q7. Write a lambda function to add 10 to a given integer.
Q8. How to raise an exception with arguments.
[Link] the methods of re package.
Q10. What is a wb mode in file?
Q11. What is a package? Explain with example how to create a package.
Q12. What are the usage of tuples zip (), tuple(), count() and index() functions?
Q13. What is an anonymous function? How to create it? Explain with example.
Q14. Explain the following loops with example.
i) While
ii) For
Q15. How to perform input output operations? Explain with example.
Q16. Write a program to accept a string from user and display the string in
reverse order eliminating the letter ‘s’ from the string.
Q17. Write a program to raise a user defined exception to check if age is
less that 18.
Q18. Write a Python program to check that a string contains only a certain set
of characters (in this case a-z, A-Z and 0-9).
Q19. Write a Python program to add ‘ing’ at the end of a given string (length
should be at least 3). If the given string already ends with 'ing', add 'ly'
instead. If the string length of the given string is less than 3, leave it
unchanged.
Q20. Write a Python program to combine values in a list of dictionaries. Sample
data: [{'item': 'item 1', 'amount': 400}, {'item': 'item2', 'amount': 300},
{'item': 'item1', 'amount': 750}]
Expected Output: Counter ({'item1': 1150, 'item2': 300}).
Q21. Write a Python program to extract year, month, date and time using
Lambda.
Q22. How are comments written in Python?
Q23. Give the use of index() in string.
Q24. Explain the range() function and its parameters.
Q25. How to create a void function in Python?
Q26. What is the difference between pop() and del in list.
Q27. Compare list and tuple (any two points).
Q28. What does the following functions return - clock() and gmtime().
Q29. List the syntax for handling exception.
Q30. List any two functions in math module.
Q31. Explain the function enumerate().
Q32. Which methods are used to read from a file? Explain any two with example.
Q33. What are the usage of dictionary copy(), gets(), items() and keys()
methods?
Q34. Explain union and intersection with example.
Q35. Explain the following statement
i) if b) if else c) break d) continue
Q36. List features of Python.
Q37. Write a program to get a single string from two given strings, separated by
space and swap the first two characters of each string
Sample input: ‘abc’, ‘pqr’ Output: pqc abr
Q38. Write a program to display power of 2 upto a given number using
anonymous function
Example
N=2
2 raised to 0 is 1
2 raised to 1 is 2
2 raised to 2 is 4
Q39. Write a program to read an entire text file.
Q40. Write a python program to Count Vowels and Consonants in a String.
Q41. Write a Python script to print a dictionary where the keys are numbers
between 1 and 15 (both included) and the values are the square of the keys.
Sample Dictionary
{1: 1, 2:4, 3:9, 4: 16, 5:25, 6:36, 7:49, 8:64, 9:81, 10: 100, 11: 121, 12: 144,
13: 169, 14: 196, 15: 225}
Q42. Write a Python function that accepts a string and counts the number of upper
and lower case letters.
Q43. a = True b = False c = False if not a or b:
print (1)
elif not a or not b and c: print (2)
elif not a or b or not b and a:
print (3) else:
print (4)
Q44. def f1(x, 1=[ ]):
for i in range(x):
[Link](i*i)
print(1)
f1 (2)
f1 (3,[3,2,1])
f1 (3)
Q45. What is the purpose of range ( ) function?
Q46. What is a list? Explain with suitable example.
Q47. What is copysing ( ) function?
Q48. How are tuples created?
Q49. What is a uniform ( ) method?
[Link] to create a package?
[Link] is a ‘wb’ mode in file?
Q52. What is the use of finally block?
Q53. Give the use of index ( ) method of string.
Q54. Python is a scripting language comment.
Q55. Explain the filter function with example.
Q56. Explain any two list methods with example.
Q57. Explain any two basic string methods.
Q58. Explain the concept of slicing with suitable example
[Link] are modules? Explain with example how to import modules.
Q60. Which methods are used to read from file? Explain any two of them with
example.
Q61. Write a python program to check if a given string as palindrome or not.
Q62. Write a program to find GCD of number using recursion.
Q63. List the various methods of re package explain any two methods in detail
with example.
Q64. Write a python program to find sum of digits of a number (Accept number
from user).
Q65. Write a python program to append the contents of file 2 to file 1. Acept
file names from user.
Q66. What will be the output of the following code
r = lambda q : q*2
s= lambda q : q*3
x=2
x = r(x)
x = s(x)
x = r(x)
print (x)
Q67. What will be the output of the following.
code
count = 1
def do This ( ) :
global count
for i in (1 , 2, 3)
Count + =1
do This ( )
print (Count)