30 Python Basic Exercises for Beginners with Solutions
Master beginner Python skills with our comprehensive list of top 30 exercises. Dive into coding challenges that improve your understanding and proficiency in Python, setting a solid foundation for intermediate challenges. Start your journey to Python mastery today!
Learning Objectives:
By the end of these exercises, you will have a strong understanding of Python loops, conditionals, and basic data structures like lists and dictionaries.
Exercise Instructions:
- Start with the first exercise and attempt to solve it before checking the hint or solution.
- Ensure you understand the logic behind each solution, as this will help you in more complex problems.
- Use these exercises to reinforce your learning and identify areas that may require further study.
1. Find the sum of two numbers
Required Input:
4, 5
Expected Output:
9
Code In Python
Output
Click Run Button to view compiled output
2. Determine if a number is even or odd
Required Input:
7
Expected Output:
Odd
Code In Python
Output
Click Run Button to view compiled output
3. Find the largest of three numbers
Required Input:
3, 9, 2
Expected Output:
9
Code In Python
Output
Click Run Button to view compiled output
4. Reverse a string
Required Input:
hello
Expected Output:
olleh
Code In Python
Output
Click Run Button to view compiled output
5. Check if a string is a palindrome
Required Input:
madam
Expected Output:
True
Code In Python
Output
Click Run Button to view compiled output
6. Calculate the factorial of a number
Required Input:
5
Expected Output:
120
Code In Python
Output
Click Run Button to view compiled output
7. Find the sum of all numbers in a list
Required Input:
[1, 2, 3, 4, 5]
Expected Output:
15
Code In Python
Output
Click Run Button to view compiled output
8. Count the number of vowels in a string
Required Input:
education
Expected Output:
5
Code In Python
Output
Click Run Button to view compiled output
9. Generate the Fibonacci sequence up to n terms
Required Input:
5
Expected Output:
[0, 1, 1, 2, 3]
Code In Python
Output
Click Run Button to view compiled output
10. Find the second largest number in a list
Required Input:
[4, 3, 1, 2]
Expected Output:
3
Code In Python
Output
Click Run Button to view compiled output