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

Python Daily Practice

Uploaded by

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

Python Daily Practice

Uploaded by

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

Very Easy Questions (100)

1. What is the keyword to define a function in Python?


2. How do you create a comment in Python?
3. What symbol is used for multiplication in Python?
4. What function is used to get the length of a list?
5. How do you create an empty dictionary?
6. How do you convert a string to an integer?
7. What is the output of print(2 + 3)?
8. How do you write "Hello, World!" to the console?
9. What keyword is used to start a loop?
10. How do you import the math module?
11. What is the output of print(10 // 3)?
12. How do you create a list with the numbers 1, 2, and 3?
13. What function is used to read input from the user?
14. What is the syntax to create a tuple with a single element?
15. How do you check if a key exists in a dictionary?
16. What is the output of print(2 ** 3)?
17. How do you create a set in Python?
18. What method is used to add an element to a list?
19. How do you create a string variable?
20. What is the output of print(5 % 2)?
21. How do you create a new file in write mode?
22. What keyword is used to handle exceptions?
23. How do you write a for loop that iterates from 0 to 4?
24. What is the output of print('Hello' + ' ' + 'World')?
25. How do you remove an element from a list by index?
26. What is the syntax for a single-line if statement?
27. How do you define a class in Python?
28. What is the output of print(type(3.14))?
29. How do you check if a value is in a list?
30. What function is used to find the maximum value in a list?
31. How do you concatenate two lists?
32. What is the output of print(3 > 2)?
33. How do you create a variable with a floating-point number?
34. What is the keyword to define a conditional statement?
35. How do you find the index of an element in a list?
36. What is the output of print('Python'[0])?
37. How do you remove whitespace from the beginning and end of a string?
38. What function is used to get the absolute value of a number?
39. How do you check if two variables are equal?
40. What is the syntax to create a multiline string?
41. How do you slice a list to get the first three elements?
42. What is the output of print(7 <= 8)?
43. How do you create a dictionary with keys 'a' and 'b'?
44. What method is used to add a key-value pair to a dictionary?
45. How do you check the data type of a variable?
46. What is the output of print('Python'.lower())?
47. How do you iterate over the keys in a dictionary?
48. What function is used to round a number to the nearest integer?
49. How do you create a list with repeated elements?
50. What is the output of print(9 % 4)?
51. How do you open a file for reading?
52. What is the keyword to return a value from a function?
53. How do you create a list comprehension that squares each element in a list?
54. What is the output of print('apple'.upper())?
55. How do you remove an element from a dictionary by key?
56. What is the syntax to define a method in a class?
57. How do you create a set with the elements 'a', 'b', and 'c'?
58. What is the output of print(len('Python'))?
59. How do you check if a string starts with a specific substring?
60. What function is used to get the minimum value in a list?
61. How do you convert a list to a tuple?
62. What is the output of print(10 < 5)?
63. How do you create a dictionary comprehension that maps numbers to their squares?
64. What is the syntax to create a nested list?
65. How do you replace a substring in a string?
66. What is the output of print(4 + 5 * 2)?
67. How do you check if a set is a subset of another set?
68. What function is used to sort a list?
69. How do you create a list of numbers from 1 to 10?
70. What is the output of print(7 - 3)?
71. How do you create a class with an initializer method?
72. What is the keyword to raise an exception?
73. How do you create a string with a variable value inside it?
74. What is the output of print('banana'.find('n'))?
75. How do you get the keys of a dictionary as a list?
76. What function is used to sum the elements of a list?
77. How do you check if a list is empty?
78. What is the output of print(8 / 2)?
79. How do you create a list with a range of numbers?
80. What is the syntax for a while loop?
81. How do you find the length of a string?
82. What is the output of print(5 == 5)?
83. How do you create a dictionary with a default value for missing keys?
84. What is the syntax to create an instance of a class?
85. How do you check if a value is not in a list?
86. What is the output of print('Hello'.replace('e', 'a'))?
87. How do you merge two dictionaries?
88. What is the syntax to create a set comprehension?
89. How do you create a list with unique elements?
90. What is the output of print(3 * 4)?
91. How do you create a list with the elements 'a', 'b', and 'c'?
92. What is the keyword to define an inheritance relationship?
93. How do you read all lines from a file into a list?
94. What is the output of print(7 // 2)?
95. How do you create a dictionary with keys and default values?
96. What function is used to reverse a list?
97. How do you create a list with mixed data types?
98. What is the output of print('Python'.startswith('P'))?
99. How do you create a dictionary from two lists?
100. What is the syntax to create a lambda function?

Easy Questions (100)

1. Write a function that returns the sum of two numbers.


2. How do you handle exceptions in Python?
3. Write a Python program to find the largest number in a list.
4. How do you write a for loop that iterates over a list of strings?
5. Write a Python function that takes a list and returns a new list with unique elements.
6. How do you write a function that returns the factorial of a number?
7. Write a Python program to count the number of vowels in a string.
8. How do you write a function that reverses a string?
9. Write a Python program to merge two dictionaries.
10. How do you write a list comprehension to create a list of even numbers?
11. Write a Python function to check if a number is prime.
12. How do you handle file operations (read/write) in Python?
13. Write a Python program to check if a string is a palindrome.
14. How do you write a function that returns the Fibonacci sequence up to a given
number?
15. Write a Python program to find the common elements in two lists.
16. How do you write a function to calculate the GCD of two numbers?
17. Write a Python program to find the intersection of two sets.
18. How do you write a function to check if a list is sorted?
19. Write a Python program to find the second largest number in a list.
20. How do you write a function to flatten a nested list?
21. Write a Python program to remove duplicates from a list.
22. How do you write a function to count the frequency of elements in a list?
23. Write a Python program to find the mode of a list of numbers.
24. How do you write a function to find the median of a list of numbers?
25. Write a Python program to find the union of two sets.
26. How do you write a function to check if a string contains only digits?
27. Write a Python program to find the maximum and minimum values in a dictionary.
28. How do you write a function to convert a list of strings to a single string?
29. Write a Python program to find the difference between two lists.
30. How do you write a function to check if two strings are anagrams?
31. Write a Python program to find the common keys in two dictionaries.
32. How do you write a function to convert a list of tuples to a dictionary?
33. Write a Python program to find the symmetric difference of two sets.
34. How do you write a function to find the longest word in a list of words?
35. Write a Python program to find the sum of elements in a list using recursion.
36. How do you write a function to find the product of elements in a list?
37. Write a Python program to find the length of the longest substring without repeating
characters.

38. How do you write a function to find the length of the longest substring without
repeating characters?
39. Write a Python program to find the first non-repeating character in a string.
40. How do you write a function to remove all occurrences of a given element from a list?
41. Write a Python program to find the sum of all even numbers in a list.
42. How do you write a function to find the most frequent element in a list?
43. Write a Python program to find the sum of the digits of a number.
44. How do you write a function to find the first missing positive integer in a list?
45. Write a Python program to find the kth smallest element in a list.
46. How do you write a function to find the longest common prefix among a list of
strings?
47. Write a Python program to find the smallest missing positive integer in a list.
48. How do you write a function to find the number of times a given substring appears in
a string?
49. Write a Python program to find the intersection of two dictionaries.
50. How do you write a function to find the common elements in three lists?
51. Write a Python program to find the average of a list of numbers.
52. How do you write a function to remove all non-alphanumeric characters from a
string?
53. Write a Python program to find the maximum product of two elements in a list.
54. How do you write a function to check if a number is a power of two?
55. Write a Python program to find the sum of squares of elements in a list.
56. How do you write a function to find the most frequent word in a string?
57. Write a Python program to find the longest increasing subsequence in a list.
58. How do you write a function to find the longest palindrome in a string?
59. Write a Python program to find the most common element in a list.
60. How do you write a function to check if a string contains any special characters?
61. Write a Python program to find the sum of all odd numbers in a list.
62. How do you write a function to find the second smallest element in a list?
63. Write a Python program to find the number of even and odd numbers in a list.
64. How do you write a function to find the sum of all positive numbers in a list?
65. Write a Python program to find the maximum difference between two elements in a
list.
66. How do you write a function to find the longest word in a string?
67. Write a Python program to find the product of all elements in a list.
68. How do you write a function to find the most frequent character in a string?
69. Write a Python program to find the length of the shortest word in a list of words.
70. How do you write a function to find the sum of elements in a list using a for loop?
71. Write a Python program to find the maximum and minimum values in a list of tuples.
72. How do you write a function to find the longest increasing subarray in a list?
73. Write a Python program to find the number of occurrences of each character in a
string.
74. How do you write a function to check if a number is a perfect square?
75. Write a Python program to find the second most frequent element in a list.
76. How do you write a function to find the number of prime numbers in a list?
77. Write a Python program to find the sum of the elements in a list using a while loop.
78. How do you write a function to check if a string contains only uppercase letters?
79. Write a Python program to find the largest sum of consecutive elements in a list.
80. How do you write a function to find the smallest and largest elements in a list of
tuples?
81. Write a Python program to find the number of words in a string.
82. How do you write a function to check if a number is a power of three?
83. Write a Python program to find the second largest element in a list using a set.
84. How do you write a function to check if a string contains only lowercase letters?
85. Write a Python program to find the most common word in a string.
86. How do you write a function to find the sum of the digits of a number using
recursion?
87. Write a Python program to find the maximum product of three elements in a list.
88. How do you write a function to check if a string contains only digits and letters?
89. Write a Python program to find the length of the longest common subsequence in two
strings.
90. How do you write a function to find the number of occurrences of a given element in
a list?
91. Write a Python program to find the length of the longest increasing subarray in a list.
92. How do you write a function to find the sum of all elements in a list using recursion?
93. Write a Python program to find the most frequent word in a list of words.
94. How do you write a function to find the product of all digits in a number?
95. Write a Python program to find the longest palindrome in a list of strings.
96. How do you write a function to find the maximum and minimum values in a list of
numbers?
97. Write a Python program to find the length of the longest substring with repeating
characters.
98. How do you write a function to find the sum of all prime numbers in a list?
99. Write a Python program to find the maximum product of two elements in a list using a
set.
100. How do you write a function to find the longest common prefix among a list
of words?

Medium Questions (70)

1. Write a Python program to find the longest increasing subsequence in a list.


2. How do you write a function to find the longest common subsequence in two strings?
3. Write a Python program to find the maximum subarray sum in a list.
4. How do you write a function to find the edit distance between two strings?
5. Write a Python program to find the longest palindrome substring in a string.
6. How do you write a function to find the number of ways to make change for a given
amount?
7. Write a Python program to find the longest increasing path in a matrix.
8. How do you write a function to solve the longest increasing subsequence problem
using dynamic programming?
9. Write a Python program to find the maximum product subarray in a list.
10. How do you write a function to find the number of islands in a grid?
11. Write a Python program to find the longest valid parentheses substring in a string.
12. How do you write a function to find the maximum sum increasing subsequence in a
list?
13. Write a Python program to find the longest repeating substring in a string.
14. How do you write a function to find the minimum number of coins needed to make
change for a given amount?
15. Write a Python program to find the maximum sum rectangle in a 2D matrix.
16. How do you write a function to find the number of distinct subsequences in a string?
17. Write a Python program to find the longest palindromic subsequence in a string.
18. How do you write a function to find the number of ways to partition a set into k
subsets?
19. Write a Python program to find the maximum path sum in a binary tree.
20. How do you write a function to find the longest alternating subsequence in a list?
21. Write a Python program to find the longest subsequence with a difference of one.
22. How do you write a function to find the maximum profit with at most two
transactions?
23. Write a Python program to find the number of ways to reach the nth stair using steps
1, 2, or 3.
24. How do you write a function to find the length of the longest arithmetic subsequence
in a list?
25. Write a Python program to find the maximum length of a chain of pairs.
26. How do you write a function to find the number of ways to tile a 2xN board using 2x1
tiles?
27. Write a Python program to find the length of the longest zigzag subsequence in a list.
28. How do you write a function to find the maximum sum of non-adjacent elements in a
list?
29. Write a Python program to find the number of ways to decode a message.
30. How do you write a function to find the length of the longest bitonic subsequence in a
list?
31. Write a Python program to find the maximum sum path in a grid.
32. How do you write a function to find the longest common substring in two strings?
33. Write a Python program to find the length of the longest increasing path in a matrix.
34. How do you write a function to find the maximum sum of pairs with a specific
difference?
35. Write a Python program to find the number of ways to paint a fence with N posts and
K colors.
36. How do you write a function to find the length of the longest subsequence with no
consecutive elements?
37. Write a Python program to find the number of ways to reach a target score using 3
different moves.
38. How do you write a function to find the longest common subsequence in three
strings?
39. Write a Python program to find the number of ways to reach the nth stair with exactly
k steps.
40. How do you write a function to find the maximum length of a contiguous subarray
with equal number of 0s and 1s?
41. Write a Python program to find the longest subarray with a sum divisible by k.
42. How do you write a function to find the longest increasing subsequence with a
specific difference?

43. Write a Python program to find the number of ways to partition a string into
palindromic substrings.
44. How do you write a function to find the longest contiguous subsequence with a
specific sum?
45. Write a Python program to find the maximum sum of elements such that no two
elements are adjacent.
46. How do you write a function to find the length of the longest subarray with a sum of
0?
47. Write a Python program to find the minimum number of operations to convert one
string to another.
48. How do you write a function to find the number of ways to partition an array into two
subsets with equal sum?
49. Write a Python program to find the longest subarray with all elements distinct.
50. How do you write a function to find the minimum number of deletions to make a
string a palindrome?
51. Write a Python program to find the number of ways to reach the nth stair with
variable steps.
52. How do you write a function to find the maximum sum subarray with at most k
distinct elements?
53. Write a Python program to find the number of ways to paint houses such that no two
adjacent houses have the same color.
54. How do you write a function to find the minimum cost to reach the last cell of a grid?
55. Write a Python program to find the maximum sum increasing subsequence with no
consecutive elements.
56. How do you write a function to find the number of distinct palindromic substrings in a
string?
57. Write a Python program to find the longest subarray with a sum less than or equal to
k.
58. How do you write a function to find the minimum number of jumps to reach the end
of an array?
59. Write a Python program to find the length of the longest balanced parentheses
substring.
60. How do you write a function to find the maximum length of a subarray with
alternating even and odd numbers?
61. Write a Python program to find the number of ways to climb a staircase with variable
steps.
62. How do you write a function to find the maximum product of a contiguous subarray?
63. Write a Python program to find the length of the longest subsequence where the
difference between adjacent elements is 1.
64. How do you write a function to find the number of ways to partition a string into k
palindromic substrings?
65. Write a Python program to find the maximum sum subarray with at most one deletion.
66. How do you write a function to find the length of the longest contiguous subarray
with a sum of k?
67. Write a Python program to find the number of ways to partition an array into k subsets
with equal sum.
68. How do you write a function to find the minimum number of operations to make all
elements of an array equal?
69. Write a Python program to find the maximum length of a subarray with the same
number of 0s and 1s.
70. How do you write a function to find the length of the longest subarray with a sum
greater than or equal to k?

Difficult Questions (50)

1. Write a Python program to implement the A* search algorithm.


2. How do you write a function to solve the Traveling Salesman Problem using dynamic
programming?
3. Write a Python program to implement the Bellman-Ford algorithm for finding the
shortest path in a graph.
4. How do you write a function to solve the 0/1 Knapsack Problem using dynamic
programming?
5. Write a Python program to implement the Floyd-Warshall algorithm for finding the
shortest path in a graph.
6. How do you write a function to solve the Longest Common Subsequence problem
using dynamic programming?
7. Write a Python program to implement the Ford-Fulkerson algorithm for finding the
maximum flow in a flow network.
8. How do you write a function to solve the Longest Increasing Subsequence problem
using binary search?
9. Write a Python program to implement the Prim's algorithm for finding the minimum
spanning tree of a graph.
10. How do you write a function to solve the Matrix Chain Multiplication problem using
dynamic programming?
11. Write a Python program to implement the Kruskal's algorithm for finding the
minimum spanning tree of a graph.
12. How do you write a function to solve the Edit Distance problem using dynamic
programming?
13. Write a Python program to implement the Dijkstra's algorithm for finding the shortest
path in a graph.
14. How do you write a function to solve the Subset Sum problem using dynamic
programming?
15. Write a Python program to implement the Hopcroft-Karp algorithm for finding the
maximum matching in a bipartite graph.
16. How do you write a function to solve the Longest Palindromic Substring problem
using dynamic programming?
17. Write a Python program to implement the Johnson's algorithm for finding the shortest
path in a graph.
18. How do you write a function to solve the Minimum Coin Change problem using
dynamic programming?
19. Write a Python program to implement the Hungarian algorithm for finding the
maximum matching in a bipartite graph.
20. How do you write a function to solve the Maximum Product Subarray problem using
dynamic programming?
21. Write a Python program to implement the Edmonds-Karp algorithm for finding the
maximum flow in a flow network.
22. How do you write a function to solve the Minimum Path Sum problem using dynamic
programming?
23. Write a Python program to implement the Boruvka's algorithm for finding the
minimum spanning tree of a graph.
24. How do you write a function to solve the Egg Dropping problem using dynamic
programming?
25. Write a Python program to implement the KMP algorithm for pattern matching.
26. How do you write a function to solve the Palindrome Partitioning problem using
dynamic programming?
27. Write a Python program to implement the Rabin-Karp algorithm for pattern matching.
28. How do you write a function to solve the Longest Palindromic Subsequence problem
using dynamic programming?
29. Write a Python program to implement the Boyer-Moore algorithm for pattern
matching.
30. How do you write a function to solve the Rod Cutting problem using dynamic
programming?
31. Write a Python program to implement the Gale-Shapley algorithm for the stable
marriage problem.
32. How do you write a function to solve the Longest Increasing Subsequence problem
using dynamic programming?
33. Write a Python program to implement the Tarjan's algorithm for finding strongly
connected components in a graph.
34. How do you write a function to solve the Edit Distance problem using dynamic
programming?
35. Write a Python program to implement the Kosaraju's algorithm for finding strongly
connected components in a graph.
36. How do you write a function to solve the Subset Sum problem using dynamic
programming?
37. Write a Python program to implement the Johnson's algorithm for finding the shortest
path in a graph.
38. How do you write a function to solve the Minimum Path Sum problem using dynamic
programming?
39. Write a Python program to implement the Edmonds-Karp algorithm for finding the
maximum flow in a flow network.
40. How do you write a function to solve the Palindrome Partitioning problem using
dynamic programming?
41. Write a Python program to implement the KMP algorithm for pattern matching.
42. How do you write a function to solve the Egg Dropping problem using dynamic
programming?
43. Write a Python program to implement the Gale-Shapley algorithm for the stable
marriage problem.
44. How do you write a function to solve the Longest Palindromic Subsequence problem
using dynamic programming?
45. Write a Python program to implement the Boyer-Moore algorithm for pattern
matching.
46. How do you write a function to solve the Rod Cutting problem using dynamic
programming?
47. Write a Python program to implement the Hungarian algorithm for finding the
maximum matching in a bipartite graph.
48. How do you write a function to solve the Longest Palindromic Substring problem
using dynamic programming?
49. Write a Python program to implement the Rabin-Karp algorithm for pattern matching.
50. How do you write a function to solve the Maximum Product Subarray problem using
dynamic programming?

Very Difficult Questions (30)

1. Write a Python program to solve the N-Queens problem using backtracking.


2. How do you write a function to solve the Sudoku puzzle using backtracking?
3. Write a Python program to solve the Knight's Tour problem using backtracking.
4. How do you write a function to solve the Hamiltonian Cycle problem using
backtracking?
5. Write a Python program to solve the Graph Coloring problem using backtracking.
6. How do you write a function to solve the Subset Sum problem using backtracking?
7. Write a Python program to solve the Word Break problem using backtracking.
8. How do you write a function to solve the Combination Sum problem using
backtracking?
9. Write a Python program to solve the Palindrome Partitioning problem using
backtracking.
10. How do you write a function to solve the Permutation Sequence problem using
backtracking?
11. Write a Python program to solve the Letter Combinations of a Phone Number
problem using backtracking.
12. How do you write a function to solve the Generate Parentheses problem using
backtracking?
13. Write a Python program to solve the Restore IP Addresses problem using
backtracking.
14. How do you write a function to solve the N-Queens II problem using backtracking?
15. Write a Python program to solve the Combinations problem using backtracking.
16. How do you write a function to solve the Subsets problem using backtracking?
17. Write a Python program to solve the Partition to K Equal Sum Subsets problem using
backtracking.
18. How do you write a function to solve the Combination Sum II problem using
backtracking?
19. Write a Python program to solve the Word Search problem using backtracking.
20. How do you write a function to solve the Unique Paths III problem using
backtracking?
21.  Write a Python program to solve the All Paths From Source to Target problem
using backtracking.
22.  How do you write a function to solve the Matchsticks to Square problem using
backtracking?
23.  Write a Python program to solve the Maximum Length of a Concatenated String
with Unique Characters problem using backtracking.
24.  How do you write a function to solve the Largest Rectangle in Histogram problem
using divide and conquer?
25.  Write a Python program to solve the Trapping Rain Water problem using two
pointers.
26.  How do you write a function to solve the Sliding Window Maximum problem
using a deque?
27.  Write a Python program to solve the Longest Substring with At Most K Distinct
Characters problem using sliding window.
28.  How do you write a function to solve the Longest Substring with At Most Two
Distinct Characters problem using sliding window?
29.  Write a Python program to solve the Minimum Window Substring problem using
sliding window.
30.  How do you write a function to solve the Longest Substring Without Repeating
Characters problem using sliding window?

You might also like