Introduction to Computers & Programming Fundamentals
What is Programming?
Programming is the process of writing instructions that a computer can understand and execute. These instructions are written in a programming language and help solve problems, automate tasks, or build software.
๐งพ 1. Introduction to Programming
Programming involves creating a set of instructions to tell a computer how to perform a task. A programmer writes code in a programming language like Python, C++, or Java. The code is then translated (compiled or interpreted) into machine language.
๐️ 2. Variables and Data Types
Variables store data that the program can use or change.
Data Types define the kind of data stored:
Integer: Whole numbers (e.g., 1, 25)
Float: Decimal numbers (e.g., 3.14)
String: Text (e.g., "Hello")
Boolean: True or False values
Example in Python:
name = "Alice"
age = 20
๐ 3. Conditional Statements
Used to make decisions in a program. Common statements include:
if
: Executes code if a condition is true.else
: Executes code if the condition is false.elif
: Used for multiple conditions.
Example:
if age >= 18:
print("You are an adult")
else:
print("You are a minor")
๐ 4. Loops
Loops let you repeat code:
For Loop: Repeats a set number of times.
While Loop: Repeats as long as a condition is true.
Example:
for i in range(5):
print("Hello")
๐งฉ 5. Functions
Functions are reusable blocks of code that perform a specific task.
Example:
def greet(name):
print("Hello, " + name)
greet("Alice")
Benefits:
Code reusability
Easier to debug
Logical structure
๐ฌ 6. Basic Input and Output
Input allows users to provide data. Output displays the result.
Example:
name = input("Enter your name: ")
print("Welcome, " + name)
This lets users interact with the program dynamically.