■ Python Beginner Programming Examples
1. Hello World
The simplest program to display text on the screen.
print("Hello, World!")
2. Add Two Numbers
A program to add two numbers and print the result.
a = 5
b = 7
print("Sum:", a + b)
3. Even or Odd Checker
Check whether a number entered by the user is even or odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
4. Simple Calculator
Perform basic math operations on two numbers.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum =", a + b)
print("Difference =", a - b)
print("Product =", a * b)
print("Division =", a / b)
5. Print Numbers 1 to 10
Use a loop to print numbers from 1 to 10.
for i in range(1, 11):
print(i)
6. Multiplication Table
Print the multiplication table for any number.
num = int(input("Enter a number: "))
for i in range(1, 11):
print(num, "x", i, "=", num * i)
7. Factorial Using Loop
Find the factorial of a number using a loop.
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial:", fact)
8. Guessing Game
A fun game where the user tries to guess a random number.
import random
secret = random.randint(1, 10)
guess = int(input("Guess a number (1–10): "))
if guess == secret:
print("■ Correct!")
else:
print("■ Wrong, the number was", secret)