Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Manual 4 - Getting Started With Python in VSCode

The lab manual provides instructions for students in the Department of Avionics Engineering to set up their Python development environment using Visual Studio Code. It outlines the steps for installing Python 3, configuring Visual Studio Code, and creating a simple Python application. Students are required to complete assignments individually and adhere to submission deadlines.

Uploaded by

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

Manual 4 - Getting Started With Python in VSCode

The lab manual provides instructions for students in the Department of Avionics Engineering to set up their Python development environment using Visual Studio Code. It outlines the steps for installing Python 3, configuring Visual Studio Code, and creating a simple Python application. Students are required to complete assignments individually and adhere to submission deadlines.

Uploaded by

azhaanfareed07
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Department of Avionics Engineering

Introduction to Information Technology

Lab Manual 4

Student Name: ___________________________


Registration Number: ___________________________
Section: ___________________________
Deadline: ___________________________
Date of Submission: ___________________________
Introduction to Information Technology Session: 2023 (AVE-9)

Institute of Space Technology, Islamabad

Important Instructions
1. Every student should have lab manual in the lab; otherwise, there will be no
evaluation and attendance.
2. Those students who have Laptop must bring it in the lab fully charged along with
chargers.
3. Students should read the manual before coming to the lab.
4. Every student will have to submit assignments individually and the deadline is the
start of the next Lab session. Assignments after the due date will not be accepted.

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 2|Page
Introduction to Information Technology Session: 2023 (AVE-9)

Experiment No. 4
Getting started with Python in VSCode
Learning objectives:

By the end of this lab, you'll be able to:

• Install Python 3.
• Install and configure Visual Studio Code and extensions on your computer.
• Create a Python file.
• Write and run Python code in Visual Studio Code.

Introduction

The first step to working with any programming language is to set up the necessary tools. Most
developers use a code editor like Visual Studio Code because these tools provide autocomplete for
code and highlight syntax errors. Code editors also provide access to a rich set of add-ons to further
enhance your development experience.

In this lab, you'll set up your Python development environment. You'll use this space to learn Python
and build several applications. You'll also learn how to use Visual Studio Code to create and run a
Python file.

By the end of this lab, you'll have installed the tools required to move forward with your goal of
building applications with Python.

Validate your Python version and installation

Before you can begin writing Python code, you'll need to install a few tools on your local computer.
You'll need the Python interpreter that compiles and runs your code, and a code editor with features
that can help you write Python code.

Python versions

We try to distinguish between Python version 2 and Python version 3. We make this distinction
because Python 2 was discontinued in 2020. The key idea is that you want to use Python 3 from now
on.

To determine if your windows computer already has Python 3:

1. To open the Command Prompt app, go to Start on the Windows Taskbar.


2. Enter cmd in the Windows search box and select the Command Prompt App in
the Best match results.
3. Enter the following command python –version and then press Enter.
4. If your PC has an older version i.e., other than Python 3.13, just uninstall it.

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 3|Page
Introduction to Information Technology Session: 2023 (AVE-9)

Note: Running python --version or py --version may not return a value or may return an error
message stating 'py' is not recognized as an internal or external command, operable program or batch
file. This indicates Python is not installed on your Windows system.

Install Python 3

1. Download Python 3.13.0 from the Python website, the latest version at this time, and then install
it on your PC.
2. After Python installs, return to the command prompt.
3. Enter the following command python --version and then select Enter to see the version of Python.

You have now successfully installed Python on your local system.

Install Visual Studio Code


With Python installed on your system, you can turn your attention to a tool for writing Python code.
Although you can use a plain text editor to create or edit Python applications, a code editor, such as
Visual Studio Code, provides a greater level of support.
You'll want to use a tool that's best suited for the unique challenges of writing code. There are plenty
of options to choose from, but many developers rely on Visual Studio Code, or VS Code. It's free and
available on Windows, macOS, and Linux. It has many features that make it easy to navigate and
compile code for all programming languages.
Microsoft provides a Python extension for Visual Studio Code. This extension offers features like
syntax highlighting, code navigation, code formatting support, and more. One feature in particular,
named IntelliSense, is invaluable when you're getting started. Intellisense provides autocomplete and
contextual help as you type. You'll install that in the next unit.

To download the Visual Studio Code installer from the Visual Studio Code website:

1. In your browser, navigate to Visual Studio Code download page. The web page displays logos
for Windows, Linux, and Mac.
2. Select and download the Visual Studio Code installer for your system (System Installer).
Most browsers give you the option to either save the file to your local computer (usually in
your Downloads folder) or immediately run the installer file.

Note: After downloading the installer, you may need to open File Explorer and navigate to
the location your web browser downloaded it. The most common location is
the Downloads folder.

3. Double-click the installer file to start the installation process and run through the setup. After
the installation is complete, Visual Studio Code launches automatically.

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 4|Page
Introduction to Information Technology Session: 2023 (AVE-9)

Install the Python extensions for VSCode

When Visual Studio Code is installed, you can install the Python extension, and, optionally, set up
other tools and settings. Visual Studio Code is a powerful code editor and a lightweight general-
purpose integrated development environment (IDE) with a wide range of extensions available to
provide functionality in various programming languages. The Python extension for Visual Studio Code
provides visual cues, such as color coding and autocomplete, and debugging tools to help you write
better Python code, and to write code faster. To install the Python extension to your existing VS Code
application, do the following steps.

1. In Visual Studio Code, select View > Extensions to open the Extensions view. The Visual
Studio Code Extensions view lists the installed extensions and recommended extensions from
the most popular on Marketplace.
2. Filter the list of available extensions by entering python in the search box at the top of the
Extensions view.
3. Select the Python extension published by Microsoft (described as IntelliSense (Pylance) and
usually the first one in the list). The details about that extension appear in a tabbed panel on the
right.

4. In either the Extensions panel, or in the main panel, select Install.


5. Similarly, install the following extensions as shown:

If you've successfully installed the above extensions in Visual Studio Code. Let's create our first Python
application!

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 5|Page
Introduction to Information Technology Session: 2023 (AVE-9)

Create your first Python application


With Python and Python tools installed, you can create
your first Python application!
1. Create an empty folder in your PC and rename it
as VSCodeDirectory_Reg.No.
2. In VSCode, click on File tab and select Add
Folder to Workspace…
3. In the Explorer view, hover over the title bar,
and then select New File.

4. Name the new file Lab4_Reg#.py by entering it into


the new textbox and pressing Enter.
By using the .py file extension, you tell VS Code
to interpret this file as a Python program, so that
it evaluates the contents with the Python
extension.

5. Enter the following Python code in the editor panel. This command uses the print function to
display the text Reg.No._Name when your application is run.

print('Reg.No._Name')

6. Save the file by selecting File and Save (or Ctrl+S).

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 6|Page
Introduction to Information Technology Session: 2023 (AVE-9)

7. Open the built-in terminal in Visual Studio Code by selecting View and Terminal.

8. In the new terminal window, run the following command to run your Python code.
python Lab4.py

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 7|Page
Introduction to Information Technology Session: 2023 (AVE-9)

Reg.No._Name appears in the terminal window. Congratulations! You've created


a Python application!
Summary
Our goal was to create a development environment to begin writing Python code.
You installed Python 3, Visual Studio Code, and the Python extensions for Visual Studio Code. You
also created your first Python application.
You've taken your first steps towards learning Python. Soon you'll be writing programs and scripts to
analyze data, run websites, and many other applications.

Select the right option


1. What is the main version of Python currently supported?
a) Python 1
b) Python 2
c) Python 3

2. What Python function is used to display information on the screen?

a) len
b) print
c) open

3. What file extension is typically used for Python files?


a) python
b) p
c) py

Department of Avionics Engineering,


Institute of Space Technology, Islamabad 8|Page

You might also like