Python Programming for Absolute
Beginners
1. Introduction to Programming
Programming is the process of writing instructions that a computer can understand and
execute. Python is one of the easiest and most popular programming languages,
especially for beginners.
2. Your First Python Program
In any editor or online Python compiler, type the following:
print("Hello, world!")
This line tells Python to print the message: Hello, world!
3. Variables and Data Types
A variable stores data. Example:
name = "Alice"
age = 25
print(name)
print(age)
4. Taking User Input
You can ask the user to enter data:
name = input("What is your name? ")
print("Hello,", name)
5. Conditions (if/else)
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
6. Loops
Use loops to repeat actions.
Example of a for loop:
for i in range(5):
print("Number:", i)
7. Functions
Functions group code for reuse:
def greet(name):
print("Hello,", name)
greet("Alice")
8. Practice Exercises
1. Ask user for two numbers and print their sum.
2. Check if a number is even or odd.
3. Print numbers from 1 to 10 using a loop.
4. Write a function to multiply two numbers.
9. Mini Project: Simple Calculator
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operation = input("Choose +, -, *, or /: ")
if operation == "+":
print("Result:", num1 + num2)
elif operation == "-":
print("Result:", num1 - num2)
elif operation == "*":
print("Result:", num1 * num2)
elif operation == "/":
print("Result:", num1 / num2)
else:
print("Invalid operation")