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

Python Questions

The document lists 75 python programming problems ranging from basic math operations and conditional statements to string manipulation and palindromes. The problems cover a wide variety of fundamental programming concepts and increase in complexity throughout the list.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python Questions

The document lists 75 python programming problems ranging from basic math operations and conditional statements to string manipulation and palindromes. The problems cover a wide variety of fundamental programming concepts and increase in complexity throughout the list.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1. Write a python program to print simple messages.

2. Write a python program to perform arithmetic operations.


3. Write a python program to calculate area of a square a2
4. Write a python program to calculate area of a rectangle l × b
5. Write a python program to calculate area of a circle πr2
6. Write a python program to calculate area of a right-angle triangle ½ × b × h
7. Write a python program to calculate perimeter of a square 4a
8. Write a python program to calculate perimeter of a rectangle 2(l+b)
9. Write a python program to calculate perimeter of a circle 2 π r
10. Write a python program to calculate square root of a given number.
11. Write a python program to calculate altitude of the isosceles triangle √(a2 − b2/4).
12. Write a python program to perform swapping of two numbers.
13. Write a python program to calculate average of given marks.
14. Write a python program to calculate simple interest. (hint:(p*t*r)/100)
15. Write a python program to generate random numbers.
16. Write a python program to convert Kilometre's to Miles.
17. Write a python program to convert Celsius to Fahrenheit.
18. Write a python program to convert Rupee to Dollar.
19. Write a python program to calculate area of equilateral triangle (√3/4)a2
20. Write a python program to check whether the person is eligible for voting or not.
21. Write a python program to check whether the person is eligible for Tirumala darshan or not.
22. Write a python program to check whether the student is pass or fail.
23. Write a python program to check whether the given number is odd or even.
24. Write a python program to check whether the given number is positive or negative number.
25. Write a python program to check whether the given character is digit or not.
26. Write a python program to display messages only if the condition is true.
27. Write a python program to implement number guessing game without using loops.
28. Write a python program to check whether the entered character is vowel or consonant.
29. Write a python program to check whether the given alphabet is capital letter or not.
30. Raju likes to double everything he has been given and his lucky number is the one which is
divisible by 2. Write a python program to find out whether the given number is raju’s lucky
number or not.
31. Write a python program to evaluate the following expression.
Y = 1.5X2+5 if 0 <= X <= 2
Y = 2x2+5 otherwise
32. If cost price and selling price of an item is input through the keyboard, write a python
program to determine whether the seller has made profit or incurred loss.
33. Write a python program to calculate the average of two internal marks of a subject with the
rules given, consider 80% of the marks from the best internal and 20% marks from the worst
internal.
34. Write a python program to check whether the person is eligible for contesting in Indian
elections.
35. Write a python program to find the largest among the three numbers.
36. Write a python program to construct truth table for AND operation.
37. Write a python program to display grade for the student based upon their percentage
obtained.
Percentage Grade
85-100 A+
70-84 A
55-69 B
40-54 C
<40 F
38. Write a python program to confirm whether a person is Lardy or Hardy or None depending
upon his height and weight.
Height Weight Person
5’ 5” 50kg to 60kg Lardy
Less than 5’ 5” 80kg to 90kg Hardy
Otherwise, None
39. Write a program to calculate commission for the input value of sales amount. Commission is
calculated as per the following rules:
i) Commission is NIL for sales amount Rs. 5000.
ii) Commission is 2% for sales when sales amount is >Rs. 5000 and <= Rs. 10000.
iii) Commission is 5% for sales amount >Rs. 10000.
40. Write a python script to calculate electricity bill based on following slab rates.
Consumption units Rate (in Rupees/Unit)
0-100 4
101-150 4.6
151-200 5.2
201-300 6.3
Above 300 8
(Hint: To get Consumption units take current Meter reading, old meter reading from the
user as input)
41. Write a python program to check whether the given character is a capital letter or small
letter or special symbol or a digit.
42. Write a program to simulate traffic charges for reaching different destinations by bus using
switch statement.
Source: Tirupati Bus Station
Destinations: Hyderabad - Ticket fare: 670/-
Vijayawada - Ticket fare: 550/-
Bangalore - Ticket fare: 430/-
Chennai - Ticket fare: 180/-
Mysore - Ticket fare: 520/-
Finally GST of 7% on base fare have to add for every ticket Transaction.
43. An insurance company calculates premium as follows:
i. If a person's health is excellent and the person is between 25 and 35 years of age and
lives in a city and is a male then premium is Rs.4 per thousand and the policy amount
cannot exceed Rs.2 lakhs.
ii. If a person satisfies all the above conditions and is female then the premium is Rs.3
per thousand and the policy amount cannot exceed Rs.1 lakh.
Write a python program to determine whether the person should be insured or not and
calculate his/her premium rate.
44. Write a python program to check whether the year is leap year or not.
45. Write a python program to print “HELLO” for 10 times.
46. Write a python program to print the mathematical table.
47. Write a python program to print even numbers for a given range.
48. Write a python program to find the factorial of a given number.
49. Write a python program to generate Fibonacci series.
50. Write a python program to find out the factors of a given number.
51. Write a python program to find out whether the given number is perfect number or not.
52. Write a python program to find out whether the given number is prime number or not.
53. Write a python program to print the factors for a given range.
54. Write a python program to print the factorial for a given range.
55. Write a python program to print the Armstrong number.
56. Write a python program to print the prime numbers for a given range.
57. Write a python program to print patterns.
*
**
***
****
*****
58. Write a python program to print “WELCOME” for 20 times.
59. Write a python program to count the number of digits in a given number.
60. Write a python program to find the sum of individual digits of a given number.
61. Write a python program to find the sum of only odd digits of a given number.
62. Write a python program to reverse a given number.
63. Write a python program to find whether the given number is palindrome number or not.
64. Write a python program to find whether the given number is Armstrong number or not.
65. Write a python program to print the numbers in the list until the encountered number is 6 in
a range of 1 to 10 using break.
66. Write a python program to display the string until the given character is matched using
break.
67. Write a python program to print the table by taking opinion from the user about future
iterations using both break and continue.
68. Write a python program to display numbers from 1 to 10 by skipping the number 6 using
continue.
69. Write a python program to know that pass does nothing by printing the values for a range.
70. Write a python program to print only negative numbers from the list using pass.
71. Write a Python program to print the number of times the string “SVEC” can be formed from
the given input string.

Expected Output:

input: acdfksekfevskdjfs
Output: 1

72. Python program to Find the Frequency of Characters in a String

Expected Output:

Enter a string: This website is awesome.


Enter a character to find the frequency: e
Frequency of e = 4

73. Python program to Count the Number of Vowels, Consonants and so on

Expected Output:

Enter a line of string: adfslkj34 34lkj343 34lk


Vowels: 1
Consonants: 11
Digits: 9
White spaces: 2

74. Everyone knows that chotu likes palindromic strings. One day, he found 2 ordinary strings s1
and s2. Now he wonders if he could make a palindrome by concatenating s1 and s2 in any
order. i.e if s1s2 or s2s1 is a palindrome.

75. Chandu is very fond of strings. (Or so he thinks!) But, he does not like strings which have
same consecutive letters. No one has any idea why it is so. He calls these strings as Bad
strings. So, Good strings are the strings which do not have same consecutive letters. Now,
the problem is quite simple. Given a string S, you need to convert it into a Good String. You
simply need to perform one operation - if there are two same consecutive letters, delete one
of them.

SAMPLE INPUT
3
abb
aaab
ababa
SAMPLE OUTPUT
ab
ab
ababa
76. Write a program to find the avg. of given numbers in a list.
77. Find and delete the duplicate elements in a list.
78. Store and print even and odd numbers in two different lists.
79. Find largest odd and largest even in a list.
80. Find intersection of 2 lists.
81. Python Program to Merge Two Lists and Sort it.
82. Python Program to Find the Second Largest Number in a List.
83. Python Program to Generate Random Numbers from 1 to 20 and Append Them to the List
84. Python Program to Read a List of Words and Return the Length of the Longest One.
85. Python Program to Swap the First and Last Value of a List.
86. Python Program to Remove the ith Occurrence of the Given Word in a List where Words can
Repeat.
87. Python Program to Find the Largest Number in a List.
88. Given an integer array, for each element in the array check whether there exist a
smaller element on the next immediate position of the array. If it exist print the smaller
element. If there is no smaller element on the immediate next to the element then print -1.
Example Input: 4 2 1 5 3 Output: 2 1 -1 3 -1
89. Write a Pandas program to select the rows where the number of attempts in the
examination is greater than 2.
Sample Python dictionary data and list labels:
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew',
'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
90. Write a Pandas program to add one row and one column in an existing DataFrame.
91. Write a Pandas program to count city wise number of people from a given of data set (city,
name of the person).
link: https://www.w3resource.com/python-exercises/pandas/python-pandas-data-frame-
exercise-28.php
92. Write a Pandas program to replace all the NaN values with mean in a column of a dataframe.
93. Write a python program to create data frame using a dictionary with the name Employee
with titles as Empid, Empname, Empdesig. Insert 10 records into it and display them. Add
the title Empcontact as a new title and display the results.
94. With a given tuple (1,2,3,4,5,6,7,8,9,10), write a program to print the first half values in one
line and the last half values in one line.
95. Write a program to read the information present in a welcome1.txt file such as student
name, roll no and also append the information such as contact address, parent details, and
city zip code and display it.
96. Write a program to count the vowels, consents, digits, and special symbols present in a file.
97. Write a python program to data frame using dictionary with the name Student with titles as
Stuid, Stuname, and StuNo. Insert 10 records into it and display them. Add the title
Studentemail as a new title and display the results.
98. Write a program to create a tuple and perform the operations of insertion, deletion, append,
and change the information in it.
99. Write a program to merge the two files and display the information.
100. Write a program to copy the information present in one file to another file.
101. Given is a data frame showing the name, occupation, salary of people. Find the
average salary per occupation.
102. Write a python program to check whether a given no is strong no or not using
functions.
103. Write a python program to check whether a given no is prime no or not using
functions.
104. Python program to Sort a List of Tuples in Increasing Order by the Last Element in
Each Tuple.
105. Program to get the difference between the two tuples.
106. Given list of tuples, remove all the tuples with length K. Input : test_list = [(4, 5), (4, ),
(8, 6, 7), (1, ), (3, 4, 6, 7)], K = 2 Output : [(4, ), (8, 6, 7), (1, ), (3, 4, 6, 7)] Explanation : (4, 5) of
len = 2 is removed.
107. Program to generate and print a dictionary that contains a number (between 1 and
n) in the form (x, x*x). Sample Input: (n=5) : Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
108. Program to get the maximum and minimum value in a dictionary.
109. Given an integer tuple, for each element in the tuple check whether there exist a
smaller element on the next immediate position of the array. If it exist print the smaller
element. If there is no smaller element on the immediate next to the element then print -1.
110. Example Input: 4 2 1 5 3 Output: 2 1 -1 3 -1
111. Python Program to Generate Random Numbers from 1 to 20 and Append Them to
the Tuple.
112. Write a python program to find the prime factors of a given number using functions.
113. Write a python program that takes an integer and forms a new integer which has
the number of digits at the ten’s place and the least significant digit in the one’s place using
functions. For ex, 452 => 32
114. Write a program to explore all 11 attributes of series in pandas.
115. Write a pandas program to remove the duplicates in a student dataset.
116. Write a pandas program to export the dataframe to excel file using any employee
dataset.
117. Write a pandas program to display employee details whose salary is >25000 and
<50000, from employee dataset and also display employee names contains character ‘s’
using compound condition.
118. Write a pandas program to apply conditional changes on employee dataset using
salary column on designation column. (Based on salaries of the employees create a new
column and assign designations to them)
119. 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).
120. Write a Python program that matches a string that has an a followed by one or more
b's.
121. Write a Python program that matches a string that has an 'a' followed by anything
ending in 'b'.
122. Write a Python program that matches a word at the beginning of a string.
123. Write a Python program that matches a word at the end of a string, with optional
punctuation.
124. Write a Python program to remove leading zeros from an IP address.
125. Write a Python program to extract year, month and date from an URL.
126. Write a Python program to match if two words from a list of words start with the
letter 'P'.
127. Write a Python program to abbreviate 'Road' as 'Rd.' in a given string.
128. Write a Python program to replace maximum 2 occurrences of space, comma, or dot
with a colon.
129. Write a Python Extract values between quotation marks of a string
130. Write a Python program to check a decimal with a precision of 2.
131. Write a Python program to insert spaces between words starting with capital letters.
132. Write a Python program to convert a camel-case string to a snake-case string.
133. Write a Python program to remove multiple spaces from a string.
134. Write a Python program to retrieve the number from the given string
135. Write a python program to work with meta character “.”

You might also like