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

Python Practice Questions

The document outlines a comprehensive list of programming exercises categorized into three main sections: Variables & Data Types, Conditional Statements, and Loops, followed by Intermediate Logic and Pattern & TCS/Tata-style Problems. Each section contains specific tasks that cover fundamental programming concepts such as variable manipulation, control flow, data structures, and algorithmic challenges. The exercises range from basic operations to more complex problems involving recursion, pattern generation, and data manipulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Python Practice Questions

The document outlines a comprehensive list of programming exercises categorized into three main sections: Variables & Data Types, Conditional Statements, and Loops, followed by Intermediate Logic and Pattern & TCS/Tata-style Problems. Each section contains specific tasks that cover fundamental programming concepts such as variable manipulation, control flow, data structures, and algorithmic challenges. The exercises range from basic operations to more complex problems involving recursion, pattern generation, and data manipulation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Variables & Data Types (1–15)

1. Swap two variables using a temporary variable.

2. Swap two variables without using a third variable.

3. Find the type of each variable: a = 5, b = 2.0, c = '5'.

4. Convert float to int.

5. Convert string to float.

6. Convert int to binary.

7. Convert binary to decimal.

8. Take two numbers as input and print their sum.

9. Write a program to accept a character and print its ASCII value.

10. Take a string and print it in reverse.

11. Count characters in a string.

12. Check if a string is a palindrome.

13. Concatenate two strings.

14. Check the length of a string.

15. Print each character in a string on a new line.

Conditional Statements (16–30)

16. Check if a number is even or odd.

17. Check if a number is positive, negative, or zero.

18. Find the largest of three numbers.

19. Check if a year is a leap year.

20. Write a calculator for +, -, *, / operations.

21. Check if a number is divisible by 5 and 7.

22. Accept age and check voting eligibility.

23. Check if a character is a vowel or consonant.

24. Accept 3 angles and check for a valid triangle.


25. Accept 3 sides and check triangle type.

26. Accept marks and print grade.

27. Accept two numbers and find LCM.

28. Accept two numbers and find HCF.

29. Check if a number is prime.

30. Print the first n prime numbers.

Loops (31–50)

31. Print numbers from 1 to 10 using while loop.

32. Print multiplication table of n.

33. Sum of first n natural numbers.

34. Factorial of a number.

35. Reverse a number.

36. Count digits in a number.

37. Sum of digits in a number.

38. Check for Armstrong number.

39. Print Fibonacci series.

40. Find all divisors of a number.

41. Print all even numbers between 1 to 100.

42. Find the GCD of two numbers using a loop.

43. Print numbers from 100 to 1.

44. Find the average of n numbers.

45. Count how many digits are even in a number.

46. Print numbers not divisible by 3 or 5.

47. Check if a number is a palindrome.

48. Print numbers from 1 to 100 skipping 7.

49. Print odd numbers using while loop.


50. Sum of squares of first n numbers.

Intermediate Logic (101–200)

Focus: Lists, tuples, dictionaries, sets, string manipulation, functions, recursion

Lists & Tuples (101–130)

101. Create a list and print all elements.

102. Sum all elements in a list.

103. Find the max value in a list.

104. Find the min value in a list.

105. Remove duplicates from a list.

106. Sort a list in ascending and descending order.

107. Find the second largest number in a list.

108. Accept list input from the user.

109. Count the frequency of elements in a list.

110. Merge two lists.

111. Find common elements in two lists.

112. Reverse a list.

113. Slice a list.

114. Convert list to tuple.

115. Multiply all numbers in a list.

116. Find the product of odd numbers in a list.

117. Replace the 3rd element in a list.

118. Find sum of elements at even indices.

119. List comprehension to square even numbers.

120. Check if an element exists in a list.


121–130. Create tuple problems similar to above.
Dictionaries & Sets (131–150)

131. Create a dictionary of 5 fruits with prices.

132. Access a value using key.

133. Update a dictionary value.

134. Add a new key-value pair.

135. Delete a key from a dictionary.

136. Iterate through dictionary items.

137. Count word frequency in a sentence.

138. Merge two dictionaries.

139. Create a set and add elements.

140. Find union of two sets.

141. Find intersection of two sets.

142. Remove element from set.

143. Check if set A is a subset of set B.

144. Difference between two sets.

145. Convert list to set.

146. Remove duplicates using set.

147. Find the length of a set.

148. Set comprehension.

149. Check if element exists in set.

150. Clear a set.

Strings & Functions (151–170)

151. Remove all spaces from a string.

152. Count vowels in a string.

153. Replace all vowels with *.

154. Capitalize the first letter of each word.


155. Split a string by a delimiter.

156. Join list of words into a string.

157. Find the most frequent character.

158. Remove punctuation from string.

159. Define a function to add 2 numbers.

160. Define a function to return even numbers from a list.

161. Recursive function to calculate factorial.

162. Recursive Fibonacci series.

163. Lambda function to square a number.

164. Map() with lambda to double list elements.

165. Filter() to find even numbers.

166. Use reduce() to sum list.

167. Function to check prime.

168. Function to count uppercase letters.

169. Function to return reverse of string.

170. Function to check palindrome.

Pattern & TCS/Tata-style Problems (201–300)

Focus: Number & star patterns, logical series, small game-like logic

Patterns (201–240)

201. Print star triangle:

markdown

CopyEdit

**

***
202. Reverse triangle.

203. Right-aligned triangle.

204. Pyramid pattern.

205. Number triangle.

206. Floyd’s triangle.

207. Pascal’s triangle.

208. Hollow square pattern.

209. Diamond pattern.

210. Inverted half pyramid.


211–220. Same patterns using numbers.
221–230. Patterns with characters (A, B, C...).
231–240. Zig-zag, butterfly, hourglass shapes.

Logic-Based / Aptitude Style (241–300)

241. Find the largest digit in a number.

242. Check if a string has all unique characters.

243. Print numbers in words (123 → One Two Three).

244. Print prime numbers in a range.

245. Print a number in reverse (with logic).

246. Find sum of multiples of 3 or 5 below 1000.

247. Find factorial without recursion.

248. Reverse a list without using reverse().

249. Check Armstrong numbers in a range.

250. Find the first non-repeating character.

251. Generate OTP using random module.

252. Shuffle a list randomly.

253. Roll a dice using random.

254. Simulate coin toss 100 times.


255. Count how many heads/tails.

256. Basic quiz game using input().

257. Find common letters between two strings.

258. Accept a date and find day of week.

259. Find longest word in a sentence.

260. Find missing number from a list of 1–n.

261. Identify duplicates in a list.

262. Check anagram strings.

263. Find sum of all prime numbers in a list.

264. Accept time in 24hr and convert to 12hr format.

265. Generate Fibonacci numbers using generator.

266. Find all substrings of a string.

267. Count how many times a digit appears in a number.

268. Find smallest missing positive integer.

269. Implement a simple calculator using functions.

270. Sum of diagonal elements in a matrix.

271. Find max occurring element in a string.

272. Print elements that occur more than once.

273. Replace every 2nd element in a list with zero.

274. Group anagrams from a list of strings.

275. Convert Roman numerals to integer.

276. Convert integer to Roman numerals.

277. Count trailing zeros in factorial.

278. Count number of set bits in binary of number.

279. Check if binary number is a palindrome.

280. Convert number to words (Indian style).


281. Sort list of strings by length.

282. Sort list of tuples by second value.

283. Sort dictionary by values.

284. Frequency count of elements in nested list.

285. Find all pairs in list with sum = k.

286. Create calculator with GUI using Tkinter.

287. Simulate banking system using functions.

288. Create a phonebook using dictionary.

289. Create a password generator.

290. Count number of uppercase, lowercase, digits.

291. Move all zeros to end of list.

292. Implement linear search.

293. Implement binary search.

294. Find common elements in 3 arrays.

295. Transpose a matrix.

296. Rotate a matrix 90 degrees.

297. Check magic square.

298. Spiral print of a matrix.

299. Snake pattern of matrix.

300. Print a chessboard pattern.

You might also like