0% found this document useful (0 votes)
10 views

Python Programming - Session 1

The document provides an introduction to computers, programming languages, and the basics of writing programs, specifically using Python. It explains how to set up the Python environment and Visual Studio Code, and includes a simple example program to calculate the weight of a metal ring. The document emphasizes the importance of analyzing problems and formulating precise instructions in programming.

Uploaded by

Naveed Malik
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Programming - Session 1

The document provides an introduction to computers, programming languages, and the basics of writing programs, specifically using Python. It explains how to set up the Python environment and Visual Studio Code, and includes a simple example program to calculate the weight of a metal ring. The document emphasizes the importance of analyzing problems and formulating precise instructions in programming.

Uploaded by

Naveed Malik
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Introduction

• What are computers?


• Talking about general purpose, binary, digital computers

• Dumb machines that need to be told what to do

• How do we tell them what to do?


• By giving them instructions

• How do we communicate with them?

• Use special languages such as Assembly, FORTRAN, C, Python etc.

• What is a program?
• Precise set of instructions to solve a problems

• Art of writing these instructions is called programming


Programming Languages

• How are instructions written?


• Human readable form

• What are programming languages?


• Specific languages developed to write computer instructions

• Some are machine like languages such as assembly or low level languages

• Others are human readable or high level languages such as FORTRAN, COBOL, C, C++, Python

• Compiled vs interpreted languages


• How do we transform a human readable program into machine understandable

• Compilation vs Interpretation
• Example: Need to cook meat to eat – compiling, Salad vegetables can be eaten as is - interpreting

• Language for the course: Python


Why Python is popular
• Easy to learn: straightforward syntax and very readable
• Versatile: can be used for a wide variety of applications, including
web development, data analysis, and scientific computing.
• Automation: powerful tool for automating repetitive tasks, such as
file handling, web scraping, and software testing.
• Machine learning and AI support: popular choice for machine
learning, artificial intelligence, and data science.
• Active community: Python has a large and supportive development
community.
• Vast ecosystem: Python has a large ecosystem of libraries for data
processing, machine learning, data science, and more.
Setting up the Python environment on your computer

• Go to the official Python website (https://www.python.org/)

• Select the latest version of Python

• Select the "Windows installer" option

• Click "Download"

• Run the installer

• Follow the on-screen instructions

• Verify the installation by opening a command prompt and typing python -V (or py -V)

• Run Python and display some interactive commands and results


Setting up VS Code as the preferred
editor
• Go to the official Visual Studio Code site: https://code.visualstudio.com/

• Locate the latest version of VS Code for your operating system

• Download the installer as an .exe file.

• Install the downloaded file:

• Run the installer and click Next until you reach Finish.

• Choose support for Python when prompted


Our first Python program
1. Open VS Code
2. Type the code
Print(“Hello World”)

3. Save as a .py file


4. Run the program highlighting the output

• Using the Python CLI when needed (will be used in operators module etc.)
Programming Basics
•To design a program properly

1. Analyze the problem


2. Express its essence, with examples
3. Formulate statements precisely
4. Evaluate, test and revise if necessary
5. Pay attention to detail
Example program:

• Find the weight of metal required to make an


annular ring with inner and outer radii 2 cm and 5
cm. The metal sheet has a grammage of 10
gms/cm2. Assume pi=3.14

• Walk through analysis, variables, precision, testing etc.


(with diagrams)
r=5c
m

• r=2cm
The program
• Find area of larger circle:
• A1 = 3.14 * 5 * 5
• Find area of smaller circle:
• A2 = 3.14 * 2 * 2
• Find area of metal sheet to make the ring
• A3 = A1 – A2
• Find the weight of the ring:
• W = A3 * 10
• Answer W is in gms
Writing this program in Python
(screen rec.)
# Find area of larger circle:
A1 = 3.14 * 5 * 5
# Find area of smaller circle:
A2 = 3.14 * 2 * 2
# Find area of metal sheet to make the ring
A3 = A1 - A2
# Find the weight of the ring:
W = A3 * 10
# Answer W is in gms
print(“The weight of the metal ring is: “, W, “ grams.”)

You might also like