Python is a popular and versatile programming language that is used for web development, data analysis, machine learning, and a variety of other applications. It cannot be easy to know where to begin if you’re new to Python, but the best way to improve your programming skills is to practice with hands-on programming exercises.
In this article, we’ll give you over 100+ Python programs for beginners to help you learn and improve your skills. Basic syntax, data types, conditionals, loops, functions, file handling, and other topics are covered in these programs.
Going through these programs will not only help you understand Python better but will also boost your confidence in your programming abilities. So, whether you’re a complete beginner or simply looking to brush up on your skills, these Python programs are the ideal way to advance your programming abilities.
Table of Contents
List of best 100+ Python Programs For Beginners
So here we have listed 100+ Python Programs For Beginners by following them you can level up your python programming skills and understanding, Simply go through each python program first understand the concept and then repeat that python program by yourself.
1. Python program to calculate the sum of two numbers.
num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) sum = num1 + num2 print("The sum of", num1, "and", num2, "is", sum)
2. Python program to find the largest number among three numbers.
num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) num3 = int(input("Enter third number: ")) largest = max(num1, num2, num3) print("The largest number among", num1, ",", num2, "and", num3, "is", largest)
3. Python program to find whether a given number is odd or even.
num = int(input("Enter a number: ")) if num % 2 == 0: print(num, "is even") else: print(num, "is odd")
4. Python program to check whether a given year is a leap year or not.
year = int(input("Enter a year: ")) if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0): print(year, "is a leap year") else: print(year, "is not a leap year")
5. Python program to check whether a given character is a vowel or consonant.
ch = input("Enter a character: ") if ch in "aeiouAEIOU": print(ch, "is a vowel") else: print(ch, "is a consonant")
6. Python program to find the factorial of a given number.
num = int(input("Enter a number: ")) fact = 1 for i in range(1, num+1): fact *= i print("The factorial of", num, "is", fact)
7. Python program to generate the Fibonacci series up to a given number.
n = int(input("Enter a number: ")) fib = [0, 1] while fib[-1] < n: fib.append(fib[-1] + fib[-2]) print("The Fibonacci series up to", n, "is", fib)
8. Python program to check whether a given string is a palindrome or not.
s = input("Enter a string: ") if s == s[::-1]: print(s, "is a palindrome") else: print(s, "is not a palindrome")
9. Python program to find the length of a given string.
s = input("Enter a string: ") length = len(s) print("The length of", s, "is", length)
10. Python program to find the sum of all the elements in a list.
lst = [int(x) for x in input("Enter a list of numbers: ").split()] total = sum(lst) print("The sum of all the elements in the list", lst, "is", total)
11. Python program to find the largest element in a list.
lst = [int(x) for x in input("Enter a list of numbers: ").split()] largest = max(lst) print("The largest element in the list", lst, "is", largest)
12. Python program to find the smallest element in a list.
lst = [int(x) for x in input("Enter a list of numbers: ").split()] smallest = min(lst) print("The smallest element in the list", lst, "is", smallest)
13. Python program to find the second largest element in a list.
lst = [int(x) for x in input("Enter a list of numbers: ").split()] largest = max(lst) lst.remove(largest) second_largest = max(lst) print("The second largest element in the list", lst, "is", second_largest)
14. Python program to reverse a given string.
s = input("Enter a string: ") reverse_s = s[::-1] print("The reverse of", s, "is", reverse_s)
15. Python program to find the sum of all the digits in a given number.
num = int(input("Enter a number: ")) sum = 0 while num > 0: digit = num % 10 sum += digit num //= 10 print("The sum of all the digits in", num, "is", sum)
16. Python program to check whether a given number is a palindrome or not.
num = int(input("Enter a number: ")) temp = num reverse_num = 0 while temp > 0: digit = temp % 10 reverse_num = reverse_num * 10 + digit temp //= 10 if num == reverse_num: print(num, "is a palindrome") else: print(num, "is not a palindrome")
17. Python program to find the GCD of two numbers.
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) gcd_num = gcd(num1, num2) print("The GCD of", num1, "and", num2, "is", gcd_num)
18. Python program to find the LCM of two numbers.
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): return (a * b) // gcd(a, b) num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) lcm_num = lcm(num1, num2) print("The LCM of", num1, "and", num2, "is
19. Python program to check whether a given number is prime or not.
def is_prime(num): if num <= 1: return False for i in range(2, int(num ** 0.5) + 1): if num % i == 0: return False return True # Example usage print(is_prime(7)) # Output: True print(is_prime(12)) # Output: False
20. Python program to find all the prime numbers in a given range.
def find_primes(start, end): primes = [] for num in range(start, end+1): if is_prime(num): primes.append(num) return primes # Example usage print(find_primes(1, 20)) # Output: [2, 3, 5, 7, 11, 13, 17, 19]
21. Python program to find the sum of all the prime numbers in a given range.
def sum_primes(start, end): primes = find_primes(start, end) return sum(primes) # Example usage print(sum_primes(1, 20)) # Output: 77
22. Python program to find the prime factors of a given number.
def prime_factors(num): factors = [] i = 2 while i <= num: if num % i == 0: factors.append(i) num = num / i else: i += 1 return factors # Example usage print(prime_factors(24)) # Output: [2, 2, 2, 3]
For a Now, We have mentioned 22 python programs but we will update them from time to time
Also Read: Best Way to Use Python script for solving mp2 equations