0% found this document useful (0 votes)
4 views16 pages

lecture 2

This document provides a hands-on introduction to Python and virtual environments, covering installation of Python, Anaconda, and Visual Studio Code, as well as verification of installations. It details steps for creating virtual environments, project folders, and files using both GUI and CLI methods, along with basic Python exercises on syntax, variables, data types, lists, dictionaries, and operators. Additional references for further exercises are also included.

Uploaded by

mukisasamuel2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views16 pages

lecture 2

This document provides a hands-on introduction to Python and virtual environments, covering installation of Python, Anaconda, and Visual Studio Code, as well as verification of installations. It details steps for creating virtual environments, project folders, and files using both GUI and CLI methods, along with basic Python exercises on syntax, variables, data types, lists, dictionaries, and operators. Additional references for further exercises are also included.

Uploaded by

mukisasamuel2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

10/1/23

HANDS-ON
INTRODUCTION TO PYTHON & VIRTUAL ENVIRONMENT

INTRODUCTION TO PYTHON &


VIRTUAL ENVIRONMENT (HANDS-ON)
WHAT ARE WE GOING TO LEARN TODAY?

Hands-On
Ø Installation
o Python
o Anaconda
o Visual Studio Code
Ø Verify Installation
Ø How to Use the Software
Ø Steps to Create a Virtual Environment, Project Folder & File
o Graphical User Interface (GUI)
o Command Line Interface (CLI)
Ø Introduction to Python (Exercise)

1
10/1/23

INSTALLATION

INSTALLATION
Setting up:
1. Python - https://www.python.org
2. Anaconda (Virtual Environment) - https://www.anaconda.com
3. Visual Studio Code (IDE) - https://code.visualstudio.com
Notes: Please install according to your Operating System (OS)

2
10/1/23

VERIFY
INSTALLATION

VERIFY INSTALLATION
PYTHON

Ø Open command prompt terminal


Ø Type “python --version” inside the terminal and your python version will be displayed

3
10/1/23

VERIFY INSTALLATION
ANACONDA (VIRTUAL ENVIRONMENT)

Ø Open anaconda prompt terminal


Ø Type “conda --version” inside the terminal and your anaconda version will be displayed

VERIFY INSTALLATION
VISUAL STUDIO CODE (VSCODE)

Ø Search “Visual Studio Code” from your search button


Ø Icon “Visual Studio Code” must appear from your
screen

4
10/1/23

HOW TO USE THE


SOFTWARE

HOW TO USE THE SOFTWARE

GRAPHICAL USER INTERFACE (GUI) COMMAND LINE INTERFACE (CLI)


ü Interact with the device/system ü Interact with the device/system
with the help of graphical with the help of various
elements commands (text-based user
interface)
ü Open “anaconda navigator” from
your search button ü Open “anaconda prompt” from
your search button

10

5
10/1/23

STEPS TO CREATE A VIRTUAL


ENVIRONMENT, PROJECT
FOLDER & FILE

11

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE
1. 2 ways in creating project folder and file: GUI & CLI
Ø Create virtual environment (venv)
Ø Create project folder in any location (i.e.: desktop)
Ø Create project file inside the created project folder
(Notes: Advice to create different virtual environment for different project. This is to avoid
dependencies conflict)
Project A Project B Project C
File A File B File C

venvA venvB venvC

12

6
10/1/23

GRAPHICAL USER INTERFACE


(GUI)

13

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (GUI)
CREATE VIRTUAL ENVIRONMENT
1. Open “anaconda navigator”
2. To start create a virtual environment, click “Environments” on 3.
the left side
3. Go to “create” button, name “the new environment” (i.e.: 4.
venvA) and select packages “python” according to your python
version. Next click “create”
4. Click your virtual environment has been created from the 5.
environment tab (i.e.: venvA)
5. Default packages has been installed in your environment

1.

2.

14

7
10/1/23

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (GUI)
CREATE PROJECT FOLDER & FILE

1. Go to your preferred location to create the folder (i.e.: desktop)


2. Create and name the new folder (i.e: project A)

Desktop

15

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (GUI)
CREATE PROJECT FOLDER & FILE

1. Go back to your “anaconda navigator” and


click “Home” on the left side
2. Make sure you have selected correct virtual
environment for your project 2.
1.
3. Launch “VS Code” from the anaconda
navigator

3.

16

8
10/1/23

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (GUI)
CREATE PROJECT FOLDER & FILE
4. From VS Code, click “File” and “Open Folder”. Select
project folder you have created (i.e.: project A)
5. An empty workspace explorer displayed from your VS
Code
6. Next, configure your CMD terminal from VS Code. Type
“ctrl + shift + p”. Search “Terminal: Select Default
Profile” and select “Command Prompt”

17

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (GUI)
CREATE PROJECT FOLDER & FILE
7. To make sure your command prompt point the correct virtual environment of your project, click icon from
your VS Code.
8. Select “Terminal”, you can find your created virtual environment (i.e.: venvA) inside the terminal with correct
project path location.
9. If all correct, you are now ready to create your project file and programmed.

18

9
10/1/23

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (GUI)
CREATE PROJECT FOLDER & FILE
10. To create project file, go to “File” and select
“New Text File”
11. An empty “Untitled-1” file will be created
from your workspace
12. Save the file by click “ctrl + s”, name the file
and save it with extension “.py” (i.e.:
main.py)
13. You can see your file in the workspace, now
you can start write your programming.
14. To run the file, you can click “play” button or
right click and choose “Run Code”
15. Output of your programmed can be
monitored from the “output” panel
(Notes: since we are using python in this work, file
extension in our project will be “.py”)

19

COMMAND LINE INTERFACE


(CLI)

20

10
10/1/23

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (CLI)
CREATE VIRTUAL ENVIRONMENT
1. Open “anaconda prompt”
2. To start create a virtual environment, type “conda create –n environment_name python=version” (i.e.:
conda create –n venvA python=3.8)
3. Activate your virtual environment by type this command “conda activate environment_name” (i.e.:
conda activate venvA)
4. Default packages has been installed in your environment. To check, type “pip list”

21

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (CLI)
CREATE PROJECT FOLDER & FILE

1. Go to your preferred location to create the folder (i.e.: desktop)


2. Create and name the new folder (i.e: project A)

Desktop

22

11
10/1/23

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (GUI)
CREATE PROJECT FOLDER & FILE
1.
1. Change project directory path from your terminal. Type “cd
project_path_location” (i.e.: cd desktop/project A). Next, press
enter.
2. Launch VS Code from your terminal by type “code .” 2.
3. VS Code will create a workspace of your project
4. Next, configure your CMD terminal from VS Code. Type “ctrl + shift +
p”. Search “Terminal: Select Default Profile” and select “Command 3.
Prompt”
7. To make sure your command prompt point the correct virtual
environment of your project, click icon from your VS Code.
4.
8. Select “Terminal”, you can find your created virtual environment (i.e.:
venvA) inside the terminal with correct project path location.
5.
9. If all correct, you are now ready to create your project file and
programmed.

23

STEPS TO CREATE VIRTUAL ENVIRONMENT,


PROJECT FOLDER & FILE (GUI)
CREATE PROJECT FOLDER & FILE
10. To create project file, go to “File” and select
“New Text File”
11. An empty “Untitled-1” file will be created
from your workspace
12. Save the file by click “ctrl + s”, name the file
and save it with extension “.py” (i.e.:
main.py)
13. You can see your file in the workspace, now
you can start write your programming.
14. To run the file, you can click “play” button or
right click and choose “Run Code”
15. Output of your programmed can be
monitored from the “output” panel
(Notes: since we are using python in this work, file
extension in our project will be “.py”)

24

12
10/1/23

INTRODUCTION TO PYTHON
(EXERCISE)

25

BASIC SYNTAX, VARIABLES & DATA TYPES

BASIC SYNTAX
1. Write a python program to print the following string in a specific format. Sample string: “Twinkle,
twinkle, little star. How I wonder what you are!”
2. Print “Learning Python is fun!”
3. Print “Hello World!”
4. Ask the user to input value 45 and print out the result as “The value is 45”

26

13
10/1/23

BASIC SYNTAX, VARIABLES & DATA TYPES

VARIABLES & DATA TYPES

1. Assign the value ‘python’ to a variable with the name “my_favourite_language”


2. Create a variable named “carname” and assign the value “Volvo” to it
3. Print the data type of the variable x, x = 5
4. Print the data type of the variable y, y = “Hello World”
5. Assign value to multiple variables in one line: x = ‘Orange’, y = ‘Banana’, z = ‘Cherry’
6. X = [‘Apple’, ‘Banana’, ‘Cherry’], print out data type for x
7. X = (‘Apple’, ‘Banana’, ‘Cherry), print out data type for x
8. X = {“name: “john”, “age”: 36}, print out data type for x

27

LISTS

1. Create a single list variable name “my_fruit” that can store item name; “apple”, “banana”, “cherry”,
“orange”
2. From Q1, print out what is the length of the variable name “my_fruit”
3. From Q1, print the second item in the variable name “my_fruit”
4. From Q1, change the value from “apple” to kiwi in the my_fruit list
5. From Q1, use the append method to add “strawberry” to the my_fruit list
6. From Q1, use the insert method to add “lemon” as the second item in the my_fruit list
7. From Q1, use the remove method to remove “banana” from the my_fruit list
8. From Q1 , use negative indexing to print the last item in my_fruit list

28

14
10/1/23

DICTIONARIES
car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

1. Use the get method to print the value of the model key of the car dictionary

2. Change the “year” value from 1964 to 2020

3. Add the key/value pair “color” : “red” to the car dictionary

4. Use the pop method to remove “model” from the car dictionary

5. Use the clear method to empty the car dictionary

29

BASIC OPERATORS
1. Given 2 operands, X = 15 and Y = 4. Print out the results:
a) X + Y
b) X – Y
c) X * Y
d) X / Y

2. Given x = 10.0, y = (x < 100.0) and isinstance(x, float). What is the value of y?
3. Suppose you have two strings:
a. “Albert Einstein is the greatest scientist in history!”
b. “Einstein is not a scientist, you dolt!”
Write a code that compares the number of characters in these two strings. Hint: Use the len() function.
4. Suppose you have a list containing the menu of a restaurant.
[“pizza”, “chicken chop”, “steak”, “fish and chips”]
Write a block of code that checks whether “kuetiau goreng”, “nasi lemak” and “chicken chop” is available
inside the list of menu.

30

15
10/1/23

REFERENCES (EXTRA EXERCISE)


1. https://www.w3resource.com/python-exercises/list/
2. https://www.w3resource.com/python-exercises/dictionary/
3. https://www.w3schools.com/python/python_operators.asp
4. https://www.tutorialspoint.com/python/python_basic_operators.htm
5. https://www.programiz.com/python-programming/operators

31

THANK YOU

32

16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy