Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Python exercises

1. Write a Python program that accepts an integer (n) and computes the value of
n+nn+nnn. Go to the editor
Sample value of n is 5
Expected Result : 615

2. 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
3. Write a Python program to test whether a number is within 100 of 1000 or 2000
4. Write a Python program to calculate the sum of three given numbers. If the values are
equal, return three times their sum
5. Write a Python program that returns a string that is n (non-negative integer) copies of
a given string.
6. Write a Python program that determines whether a given number (accepted from the
user) is even or odd, and prints an appropriate message to the user.
7. Write a Python program that will accept the base and height of a triangle and compute
its area, knowing that the triangle area is:
Area = Base * height / 2
8. Write a Python program that computes the greatest common divisor (GCD) of two
positive integers.
9. Write a Python program to find the least common multiple (LCM) of two positive
integers.
10. Write a Python program to sum two given integers. However, if the sum is between 15
and 20 it will return 20.
11. Write a Python program that displays your name, age, and address on three different
lines.
12. Write a Python program to calculate the distance between the points (x1, y1) and (x2,
y2).
13. Write a Python program to calculate the hypotenuse of a right angled triangle.
14. Write a Python program to convert all units of time into seconds.
15. Write a Python program that converts seconds into days, hours, minutes, and seconds.
16. Write a Python program to calculate sum of digits of a number.
17. Write a Python program to swap two variables.
18. Write a Python program to sum all the items in a list.
19. Write a Python program to multiply all the items in a list.
20. Write a Python program to get the largest number from a list.
21. Write a Python program to get the smallest number from a list.
22. Write a Python program to clone or copy a list.
23. Write a Python function that takes two lists and returns True if they have at least one
common member
24. Write a Python program to print the numbers of a specified list after removing even
numbers from it.
25. Write a Python program to generate and print a list of the first and last 5 elements
where the values are square numbers between 1 and 30 (both included).

You might also like