Python Programming for Beginners
1. Introduction to Python
Python is a high-level, beginner-friendly programming language known for its readability and simplicity.
It is used in web development, data science, AI, automation, and more.
2. How to Install and Run Python
1. Go to https://www.python.org/downloads/ and download the latest version.
2. Install it and make sure to check "Add Python to PATH".
3. Open IDLE (Python's editor) or install VS Code or use online compilers like Replit or Google Colab.
3. Basic Concepts in Python
- Variables: Used to store data.
- Data Types: int, float, str, bool, list, tuple, dict
- Input/Output: Use input() and print()
- If-Else: Used for decision-making
- Loops: 'for' and 'while' to repeat actions
- Functions: Reusable blocks of code
4. Beginner Programs
Example 1: Calculator
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
op = input("Enter operator (+, -, *, /): ")
if op == "+":
print(num1 + num2)
elif op == "-":
print(num1 - num2)
elif op == "*":
print(num1 * num2)
elif op == "/":
Python Programming for Beginners
print(num1 / num2)
else:
print("Invalid operator")
Example 2: Number Guessing Game
import random
number = random.randint(1, 10)
guess = int(input("Guess a number between 1 and 10: "))
if guess == number:
print("You guessed it!")
else:
print(f"Wrong! The number was {number}")
Example 3: Even or Odd Checker
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Example 4: Pattern Printing
for i in range(1, 6):
print("*" * i)
Example 5: Simple Chatbot
name = input("What is your name? ")
print("Hello", name)
question = input("How are you? ")
if "good" in question.lower():
print("Nice to hear that!")
else:
print("Hope your day gets better!")
Python Programming for Beginners
5. Practice Exercises
1. Write a program to find the biggest of 3 numbers.
2. Make a program that counts from 1 to 50 but skips multiples of 5.
3. Write a function to check if a number is prime.
4. Create a program to reverse a string.
5. Build a simple calculator using functions.
6. What Next?
Once you're confident in Python basics:
- Learn object-oriented programming (OOP)
- Explore Python libraries like NumPy, Pandas, Matplotlib
- Start with Machine Learning using Scikit-Learn
- Build AI projects like chatbots, games, and models!