Python Exercises
Python Exercises
1. Write a Python program that calculates the area of a circle based on the radius entered
by the user.
2. Write a Python program that accepts the user's first and last name and prints them in
reverse order with a space between them.
3. Write a Python program that accepts a sequence of comma-separated numbers from the
user and generates a list and a tuple of those numbers.
4. Write a Python program to display the first and last colors from the following list.
color_list = ["Red","Green","White" ,"Black"]
5. Write a Python program that accepts an integer (n) and computes the value of
n+nn+nnn.
6. Write a Python program to print absolute value on number provided by the user
7. Write a Python program that prints the calendar for a given month and year.
Note : Use 'calendar' module.
8. Write a Python program to calculate the difference between a given number and 17. If
the number is greater than 17, return twice the absolute difference
9. Write a Python program to test whether a number is within 100 of 1000 or 2000
10. Write a Python program to calculate the number of days between two dates.Sample
dates : (2024, 7, 2), (2024, 7, 15)
11. Write a Python program to calculate the sum of three given numbers. If the values are
equal, return three times their sum
12. Write a Python program to get a newly-generated string from a given string where "Is"
has been added to the front. Return the string unchanged if the given string already begins
with "Is".
13. Write a Python program to count the number 4 in a given list.
14. Write a Python program to test whether a passed letter is a vowel or not.
15. Write a Python program that checks whether a specified value is contained within a
group of values.
Test Data :
3 -> [1, 5, 8, 3] : True
-1 -> [1, 5, 8, 3] : False
16. Write a Python program to print all even numbers from a given list of numbers in the
same order and stop printing any after 237 in the sequence.
numbers = [386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
958,743, 527]
17. Write a Python program that will accept the base and height of a triangle and compute
its area
18. Write a Python program that computes the greatest common divisor (GCD) of two
positive integers
19. Write a Python program to find the least common multiple (LCM) of two positive
integers
20. Write a Python program to sum three given integers. However, if two values are equal,
the sum will be zero.
21. Write a Python program to sum two given integers. However, if the sum is between 15
and 20 it will return 20.
22. Write a Python program that returns true if the two given integer values are equal or
their sum or difference is 5.
23. Write a Python program to add two objects if both objects are integers
24. Write a Python program that displays your name, age, and address on three different
lines
25. Write a Python program to solve (x + y) * (x + y).
Test Data : x = 4, y = 3
Expected Output : (4 + 3) ^ 2) = 49
26. Write a Python program to compute the future value of a specified principal
amount, rate of interest, and number of years.
49.
50. Write a program to accept a number from a user and calculate the sum of all numbers
from 1 to a given number. For example, if the user entered 10 the output should
be 55 (1+2+3+4+5+6+7+8+9+10)
51. Write a program to print multiplication table of a given number
52. Write a program to display only those numbers from a list that satisfy the following
conditions
Examples:
58. Write a program to use the loop to find the factorial of a given number.
59. Write python program to reverse a given integer number
60. Use a loop to display elements from a given list present at odd index positions
61. Calculate the cube of all numbers from 1 to a given number
62. Write a program to calculate the sum of series up to n term. For example, if n =5 the
series will become 2 + 22 + 222 + 2222 + 22222 = 24690
63. Write a program to remove the item present at index 4 and add it to the 2nd position
and at the end of the list.
64. Slice list into 3 equal chunks and reverse each chunk
65. Write a program to iterate a given list and count the occurrence of each element and
create a dictionary to show the count of each element.
66. Create a Python set such that it shows the element from both lists in a pair
67. Find the intersection (common) of two sets and remove those elements from the first
set
68. Checks if one set is a subset or superset of another set. If found, delete all elements
from that set
69.
70. Iterate a given list and check if a given element exists as a key’s value in a dictionary.
If not, delete it from the list
71. Get all values from the dictionary and add them to a list but don’t add duplicates
speed = {'jan': 47, 'feb': 52, 'march': 47, 'April': 44, 'May': 52, 'June': 53, 'july': 54, 'Aug':
44, 'Sept': 54}
72. Remove duplicates from a list and create a tuple and find the minimum and maximum
number
73. Write a Python program to convert them into a dictionary in a way that item from list1
is the key and item from list2 is the value
74. Write python program to Merge two Python dictionaries into one
75. Write a Python program to create a new dictionary by extracting the mentioned keys
from the below dictionary.
77. Write a Python program to check if value 200 exists in the following dictionary.
78. Write a program to rename a key city to a location in the following dictionary.
79. Write a python program to get the key of a minimum value from the following
dictionary
80. Write a Python program to change Brad’s salary to 8500 in the following dictionary.