30+ Simple Python Programs for Beginners With example

Learning Python sticks best when you actually write and run code, not just read about it. This is a categorized collection of 30+ simple Python programs for beginners, covering basics, numbers, strings, lists, patterns, functions, and recursion. Each program includes the code, the exact output, and a one-line explanation so that you can copy, run, and understand it immediately.
How to Run These Python Programs
You have two easy options to run any program below.
Option 1: Install Python locally. Download Python from python.org, save any code snippet as a .py file (for example, hello.py), then run it from your terminal using python hello.py.
Option 2: Use an online IDE. If you don't want to install anything yet, any online Python compiler lets you paste code and run it instantly in your browser.
For a full walkthrough of both methods, see How to Run a Python Program.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Basic Python Programs (Print, Variables, Input)
These cover the absolute fundamentals: printing output, storing values in variables, and taking input.
1. Hello, World! The classic first program every beginner writes.
Output:
2. Add Two Numbers Stores two values in variables and prints their sum.
Output:
3. Swap Two Variables Python lets you swap values in a single line without a temporary variable.
Output:
4. Take User Input and Display It Uses input() to read text typed by the user.
Output (example run):
5. Simple Interest Calculation Applies a basic formula using variables you've already learned.
Output:
For more on how Python stores different kinds of values, see Data Types in Python. If you want a structured path through fundamentals like these, see Python for Beginners.
Number Programs (Even/Odd, Prime, Factorial, Fibonacci)
Number-based programs are a staple of coding practice and common interview warm-ups.
6. Check Even or Odd Uses the modulo operator to check divisibility by 2.
Output:
7. Check Prime Number Tests whether a number has any divisor other than 1 and itself.
Output:
8. Factorial of a Number Multiplies every number from 1 up to the given number.
Output:
9. Fibonacci Series Generates a sequence where each number is the sum of the two before it.
Output:
10. Sum of Digits Extracts and adds each digit of a number one at a time.
Output:
11. Reverse a Number Builds a new number by peeling off digits from the end.
Output:
12. Armstrong Number Check Checks whether a number equals the sum of the cubes of its own digits.
Output:
String Programs (Palindrome, Reverse, Vowel Count)
Strings are one of the most practiced data types in beginner exercises, and these cover the common patterns.
13. Check Palindrome Compares a string to its own reverse.
Output:
14. Reverse a String Uses Python's slicing shortcut to reverse text instantly.
Output:
15. Count Vowels in a String Loops through each character and checks if it's a vowel.
Output:
16. Count Words in a Sentence Splits a sentence on spaces and counts the pieces.
Output:
17. Check Anagram Two words are anagrams if their sorted letters match exactly.
Output:
18. Count Occurrences of a Character Uses the built-in .count() method to count a specific letter.
Output:
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
List Programs (Max/Min, Sum, Sort, Duplicates)
Lists are where beginners start combining loops, conditions and built-in functions together.
19. Find Maximum and Minimum in a List Uses Python's built-in max() and min() functions.
Output:
20. Sum of List Elements Adds up every value in a list using sum().
Output:
21. Sort a List Arranges list elements in ascending order using .sort().
Output:
22. Remove Duplicates from a List Converts the list to a set to drop repeated values, then sorts it for a predictable order.
Output:
23. Find the Average of List Elements Divides the sum of the list by its length.
Output:
24. Count Occurrences of an Element in a List Uses .count() to check how often a value appears.
Output:
Pattern Programs (Stars, Numbers, Pyramids)
Pattern programs build your comfort with nested loops, a skill that carries directly into more advanced logic.
25. Right Triangle Star Pattern Prints one more star on each row using an increasing loop counter.
Output:
26. Inverted Right Triangle Pattern Same idea as above, but the loop counts downward instead of up.
Output:
27. Pyramid Pattern Combines spaces and stars so the shape stays centered.
Output:
28. Number Triangle Pattern Uses a nested loop to print increasing counts of numbers on each row.
Output:
29. Diamond Pattern Builds a pyramid, then mirrors it upside down underneath.
Output:
Turn Learning into Career Growth
Function & Recursion Programs
These programs introduce functions and recursion, two ideas that show up constantly once you move past basic scripts.
30. Factorial Using Recursion The function calls itself with a smaller number until it reaches the base case.
Output:
31. Fibonacci Using Recursion Each call adds the two previous Fibonacci values together.
Output:
32. GCD of Two Numbers Using Recursion Uses the Euclidean algorithm, one of the oldest recursive techniques in math.
Output:
33. Simple Calculator Using Functions Wraps each arithmetic operation in its own reusable function.
Output:
For a deeper look at writing and organizing functions like these, see Functions in Python and the official Python tutorial.
What to Build Next (Mini Projects)
Once these programs feel comfortable, the natural next step is combining several concepts into a small, complete project rather than isolated snippets.
A few beginner-friendly ideas: a basic calculator that takes user input instead of fixed numbers, a number-guessing game using random numbers and loops, a simple to-do list stored in a list, or a program that solves a quadratic equation using the values a user enters.
For a curated set of beginner project ideas, see Python Projects for Beginners. If you're ready for a more structured, guided path beyond self-practice, see Scaler Academy or browse the full course catalogue.
FAQs
What are some simple Python programs for beginners?
Programs like adding two numbers, checking even or odd, calculating a factorial, generating a Fibonacci series, checking for a palindrome, and printing star patterns are all common beginner exercises.
How do I start practising Python programs?
Install Python locally or use an online IDE, then work through small programs covering variables, loops, conditionals and functions, building up from basics to more complex logic.
Are these Python programs good for interviews?
Yes. Number, string, list and pattern programs are common warm-up questions in coding interviews, since they test whether you can translate logic into working code quickly.
What should I learn before writing Python programs?
Basic syntax, data types, operators, conditionals and loops are the essential building blocks. Most of the programs in this guide only need these fundamentals.
What can I build after these programs?
Small projects like a calculator, a to-do list app, or a number-guessing game are natural next steps once individual programs feel comfortable.
Where can I run Python code online?
Any online Python compiler lets you paste and run code directly in a browser, or you can install Python locally from python.org and run files from your terminal.




