PYTHON EXERCISES
1. Write a program to calculate the sum of all even numbers from 1 to 100 using a loop.
2. 2. Given a list of integers, print the sum of all elements that are divisible by both 3 and 5.
List: A = [10, 15, 30, 7, 45, 60, 2]
3. Write a program that prints the following pattern using loops:
*
* *
* * *
* * * *
* * * * *
4. Write a Python program to print the following star pyramid pattern using loops:
* *
* * *
* * * *
* * * * *
5. Write a program to count the number of vowels and consonants in a given word.
6. 10. Write a program to print the largest element in a list without using max().
List: [12, 67, 89, 23, 55]
7. Write a Python program to print the capital letter ‘A’ using stars (*) in a hollow pyramid style with 4
rows.
The output should look like this:
*
* *
* * * * *
* *
8. Write a Python program to print a hollow square of stars (*) with 4 rows and 4 columns.
Expected Output:
* * * *
* *
* *
* * * *
9. Write a Python program to:
• Take 3 side lengths from the user.
• Check if a triangle is valid using the triangle inequality rule.
• If valid, check whether it is:
Equilateral (all sides equal)
Isosceles (two sides equal)
Scalene (all sides different)
10. Write a Python program to check whether a given year is a leap year or not.
A year is a leap year if:
• It is divisible by 4, and
• Not divisible by 100, unless it is also divisible by 400.