10 Basic Python Programs Every Beginner Should Write and Run
The fastest way to learn Python is to write actual programs. In this guide, you'll work through 10 foundational Python programs, each one teaching a core concept. Every example can be run directly in our free online Python compiler — no installation needed.
Program 1 — Hello, World!
print("Hello, World!")
Teaches: The print() function.
Program 2 — Simple Calculator
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print(f"Sum: {a + b}")
print(f"Difference: {a - b}")
print(f"Product: {a * b}")
print(f"Quotient: {a / b if b != 0 else 'undefined'}")
Teaches: input(), type conversion, arithmetic operators, f-strings.
Program 3 — Check Even or Odd
number = int(input("Enter a number: "))
if number % 2 == 0:
print(f"{number} is Even")
else:
print(f"{number} is Odd")
Teaches: Modulo operator, conditionals.
Program 4 — Multiplication Table
n = int(input("Enter a number: "))
for i in range(1, 11):
print(f"{n} x {i} = {n * i}")
Teaches: For loops, range().
Program 5 — Fibonacci Sequence
n = int(input("How many Fibonacci numbers? "))
a, b = 0, 1
for _ in range(n):
print(a, end=" ")
a, b = b, a + b
print()
Output for n=8: 0 1 1 2 3 5 8 13
Program 6 — Reverse a String
text = input("Enter a string: ")
print("Reversed:", text[::-1])
if text == text[::-1]:
print(f'"{text}" is a palindrome!')
Teaches: Python slicing.
Program 7 — Number Guessing Game
import random
secret = random.randint(1, 100)
attempts = 0
while True:
guess = int(input("Your guess (1-100): "))
attempts += 1
if guess < secret:
print("Too low!")
elif guess > secret:
print("Too high!")
else:
print(f"Correct in {attempts} attempts!")
break
Teaches: import random, while loops, break.
Program 8 — Find Largest in List
numbers = [42, 17, 89, 5, 73, 31, 96, 8]
largest = max(numbers)
print(f"List: {numbers}")
print(f"Largest: {largest}")
Program 9 — Word Counter
sentence = input("Enter a sentence: ")
words = sentence.split()
print(f"Word count: {len(words)}")
print(f"Character count: {len(sentence.replace(' ', ''))}")
print(f"Longest word: {max(words, key=len)}")
Program 10 — Grade Calculator
def get_grade(score):
if score >= 90: return "A"
elif score >= 80: return "B"
elif score >= 70: return "C"
elif score >= 60: return "D"
else: return "F"
students = {
"Alice": [92, 88, 95],
"Bob": [72, 68, 75],
"Carol": [85, 90, 88],
}
for name, scores in students.items():
avg = sum(scores) / len(scores)
print(f"{name}: avg={avg:.1f}, grade={get_grade(avg)}")
Teaches: Functions, dictionaries, list operations.
Frequently Asked Questions
What Python version do these programs use?
All examples use Python 3. Our compiler always runs the latest stable Python 3 release.
What should I learn after these basics?
Explore lists, dictionaries, file I/O, then pick a path — data science, web development, or automation.
Is Python good for competitive programming?
Yes, though C++ is faster for time-critical problems. Practise in our Python Compiler first, then move to C++ for speed-critical submissions.
Run All 10 Programs
Open the Free Online Python Compiler, copy any program, click Run — results in milliseconds.
Topics
Found this article helpful? Share it with others!