Introduction to Python

1. What is Programming Language?

    1.1 Real World Scenario:
    1. Imagine you have a friend who only speaks Spanish. You want to tell your friend: Please go to the market and buy some fruits. If you speak only English, your friend may not understand you. To communicate, you need to use a language that your friend understands — Spanish.
Programming Language
Programming Language Analogy
    1.2 How Does This Relate to Computers?
    1. Computers are like that Spanish-speaking friend. They do not understand English or your language directly. A computer understands only Machine Language, which consists of binary digits: 0 and 1. However, writing instructions using only 0s and 1s is very difficult for humans. Therefore, we use Programming Languages as a bridge between humans and computers. Programming languages help us write instructions in a human-friendly way, which are then translated into machine language for the computer to understand. 👦 → 💬 English → ❌💻 👦 → 🐍 Python → ✅💻 Some popular programming languages are Python, Java, C, JavaScript, etc.
    1.3 Definition
    1. A programming language is a set of instructions and rules used to create computer programs and communicate with a computer to perform specific tasks. Example Python Code: print("Hello Students!") Output: Hello Students! Here, the print() function tells the computer to display the given message on the screen.

2. Why Python?

Python Features
Features of Python
  • 😊 Easy to Learn and Read: Python has a simple syntax that is easy to read and write. This makes it a great language for beginners.
  • 🆓 Open Source: Python is free to use, and anyone can download, study, and modify it.
  • 👥 Large Community and Libraries: Python has a large community of developers around the world. It also provides many libraries (pre-written code) that help programmers perform tasks more quickly and easily.
  • 🔄 Flexible Styles: Python lets you write code step-by-step (like a recipe) or organize it into reusable "objects" (like building blocks). Beginners don't need to worry about this yet — Python allows both.
  • Multiple Usages: Widely used in various fields such as: - 📊 Data Science - 🤖 Artificial Intelligence - 🌐 Web Development - 🔧 Automation - 🎮 Game Development

3. IDE (Integrated Development Environment)

    3.1 Real World Scenario:
    1. Imagine you have learned Spanish and now want to ask your Spanish-speaking friend to buy some fruits. Knowing the language alone is not enough. You also need a way to communicate with your friend, such as: Writing a Letter, Sending a Text Message, Making a Phone Call. These methods act as a medium of communication. Similarly, even after learning a programming language like Python, we need a tool to write, edit, and execute our instructions for the computer. These tools are called Integrated Development Environments (IDEs). Popular IDEs: Visual Studio Code (VS Code), PyCharm, Jupyter Notebook, Google Colab, etc
IDE
What is an IDE?
    3.2 Definition
    1. An Integrated Development Environment (IDE) is a software application that provides tools for writing, editing, running, and debugging computer programs.
    3.3 What Can an IDE Do?
    1. 📝 Write and edit code
    2. ▶️ Run programs
    3. 🐛 Find and fix mistakes in your code (this is called "Debugging")
    4. 🎨 Highlight code for better readability (Syntax Highlighting)
    5. 📂 Manage and organize projects

4. Connecting Concepts

Real WorldProgramming
🇪🇸 Spanish Language🐍 Python Language
👦 Spanish Speaking Friend💻 Computer
☎️ Letter / Text Message / Phone🛠️ IDE
💬 Message📜 Program / Code
Connecting Real World Concepts to Programming Concepts

5. Installation and Setup

6. Google Colab

    6.1 What is Google Colab?
    1. Google Colab is a free online coding platform that allows you to write and run Python code directly from your web browser. It is based on Jupyter Notebook and requires no installation. Code written here will be saved in Google Drive automatically.
Step to Use Google Colab
Steps to Use Google Colab
    6.2 How to use Google Colab?
    1. Open Google Colab in browser
    2. Click + New Notebook on bottom left to create new file with meaningful name
    3. Add code cells using + Code button from top bar
    4. Write Python code in cells
    5. Click ▶️ Run or press Shift + Enter

7. Sample Codes

  • print("Hello, World!") # ➜ "Hello, World!"
  • print(2 + 3) # ➜ 5
  • print("Python" + " " + "Programming") # ➜ "Python Programming"
  • age = 25 new_age = age + 5 print(new_age) # ➜ 30
  • Write a code to calculate density of object with mass 2400kg and volume 1200 m3.mass = 2400volume = 1200density = mass / volumeprint(density) # ➜ 2.0
  • Note: Your file should be saved with .py or .ipynb extension to run in VS Code or any other IDE.

Practice QuestionsNot started

  1. Write a code in Google Colab to solve the question below:

    Question 1 of 2

      Initialize num_1 as -5 and num_2 as 10.45
      1. Display their sum
      2. Display their difference
      3. Display their product
      4. Display their division
      5. Display their remainder
  2. Create a folder named python_lab and open it in VSCode.

    Question 2 of 2

      Inside python_lab folder, create a new folder named introduction. In the introduction folder, solve each questions in a separate Python file. Name the files ex_1.py, ex_2.py and so on:
      1. 🌡️ Normal human temperature is 98.6 °F. Convert it to Celsius. C = (F - 32)/1.8
      2. 💰 Calculate simple interest for Rs. 50,000 at rate 6.5% p.a for 4 years. SI = PTR/100
      3. ⭕ Calculate area & perimeter of circle with diameter 12 cm. A=πr², P=2πr
      4. ⏱️ Calculate the total seconds in 3 hours, 20 minutes and 45 seconds.
      5. 📚 Calculate the average of 5 subjects where marks are: 78, 85, 62, 90, 88.
      6. 🛣️ Convert the distance of 15 kilometers to miles. 1 km = 0.621371 miles
      7. 🏃 Calculate the BMI for a person with weight 70 kg and height 1.75 m. BMI = wt / ht²)