Programming basics for absolute beginners
Never coded before? Learn variables, conditions, loops, functions and lists in plain English, with tiny Python examples and exercises.
What a program is
A program is a list of instructions the computer follows one by one. You write them in a programming language (we use Python here because it reads almost like English), and the computer runs them.
You can run every example on this page in a free online Python editor — no installation needed.
1. Printing
print("Hello, ManiaJobs!")Hello, ManiaJobs!
Shows the text on the screen. Text always goes inside quotes.
2. Variables — boxes with names
Definition: A variable is a name bound to a value stored in memory; a data type defines what kind of value it is and which operations are allowed on it.
How it works: Python is dynamically typed (the type belongs to the value, checked at run time) and strongly typed (it won't silently mix incompatible types like "5" + 3). Built-in types: int, float, str, bool, list, tuple, dict, set, None.
Example: age = 21 binds the name age to an int object; type(age) → <class 'int'>.
🧒 In simple words
name = "Asha"
age = 21
cgpa = 8.4
print(name, "is", age)Asha is 21
A variable stores a value so you can use it later. = means "put this value in the box".
| Type | Example | Used for |
|---|---|---|
| int | 21 | whole numbers |
| float | 8.4 | decimals |
| str | "Asha" | text |
| bool | True / False | yes/no |
3. Input and maths
a = int(input("First number: "))
b = int(input("Second number: "))
print("Sum:", a + b)First number: 4 Second number: 5 Sum: 9
input() always gives text, so int() turns it into a number. Operators: + - * /, // (whole division), % (remainder), ** (power).
4. Conditions — making decisions
Definition: Conditional statements execute different blocks of code depending on whether a Boolean condition is true.
How it works: if checks the first condition, elif checks further ones only if previous ones were false, and else runs when none matched. Python uses indentation to mark blocks.
Example: If marks ≥ 75 print "Distinction", elif ≥ 60 "First class", else "Keep going".
🧒 In simple words
marks = 72
if marks >= 75:
print("Distinction")
elif marks >= 60:
print("First class")
else:
print("Keep going!")First class
Python uses indentation (4 spaces) to know which lines belong to the if.
5. Loops — repeat work
Definition: A loop repeatedly executes a block of code: a for loop iterates over each item of an iterable, a while loop repeats while a condition stays true.
How it works: range(start, stop, step) produces numbers for counting loops. break exits the loop early, continue skips to the next iteration. Avoid infinite while loops by changing the condition inside.
Example: Adding every order amount in a list to a running total.
🧒 In simple words
for i in range(1, 6):
print(i) # 1 2 3 4 5
count = 3
while count > 0:
print(count)
count = count - 11 2 3 4 5 3 2 1
Use for when you know how many times, while when you repeat until something changes.
6. Lists — many values in one variable
Definition: A list is an ordered, mutable collection that can hold items of any type, accessed by zero-based index.
How it works: Supports indexing a[0], slicing a[1:3], append, insert, pop, sort. Appending is amortised O(1); searching with in is O(n).
Example: marks = [78, 91, 65]; marks.append(88).
🧒 In simple words
marks = [78, 91, 65, 88]
print(marks[0]) # 78 (counting starts at 0)
marks.append(70)
print(len(marks), max(marks), sum(marks) / len(marks))78 5 91 78.4
7. Functions — reusable blocks
Definition: A function is a named, reusable block of code that takes inputs (parameters), performs a task and optionally returns a result.
How it works: Defined with def. Parameters can have default values and be passed by keyword. Variables created inside a function are local. Functions are first-class objects, so they can be passed to other functions.
Example: def bill(amount, gst=0.05): return amount * (1 + gst).
🧒 In simple words
def grade(m):
if m >= 90: return "A"
if m >= 75: return "B"
return "C"
print(grade(88)) # BB
A function takes inputs (parameters), does a job and returns a result.
8. Dictionaries — look things up by name
Definition: A dictionary is a mutable mapping of unique, hashable keys to values, implemented as a hash table.
How it works: Lookup, insert and delete are average O(1). Keys are usually strings or numbers; values can be anything. Since Python 3.7 dictionaries keep insertion order. JSON objects map directly to dicts.
Example: student = {"name": "Ravi", "cgpa": 8.1}; student["cgpa"] → 8.1.
🧒 In simple words
student = {"name": "Ravi", "branch": "ECE", "cgpa": 8.1}
print(student["branch"])
student["city"] = "Vizag"ECE
9. Thinking like a programmer
- Understand the problem with one small example.
- Write the steps in plain English first.
- Turn each step into code.
- Test with normal, empty and extreme inputs.
- Fix one error at a time — read the error message, it tells you the line.
Exercises (answers below)
- Print your name 5 times.
- Ask for a number and say if it is even or odd.
- Print the multiplication table of 7.
- Find the largest of three numbers.
- Add all numbers from 1 to 100.
- Count the vowels in a word.
- Reverse a string.
- Write a function that checks if a number is prime.
Answers
for i in range(5): print("Asha")n = int(input()); print("even" if n % 2 == 0 else "odd")for i in range(1, 11): print(7, "x", i, "=", 7 * i)print(max(a, b, c))print(sum(range(1, 101)))→ 5050print(sum(1 for ch in word.lower() if ch in "aeiou"))print(word[::-1])def is_prime(n): return n > 1 and all(n % d for d in range(2, int(n ** 0.5) + 1))
What to learn next
Once these feel easy: strings in depth → files → object-oriented programming (classes) → data structures (stack, queue, linked list) → our coding interview patterns plan.