lecture 2
lecture 2
HANDS-ON
INTRODUCTION TO PYTHON & VIRTUAL ENVIRONMENT
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
3
10/1/23
VERIFY INSTALLATION
ANACONDA (VIRTUAL ENVIRONMENT)
VERIFY INSTALLATION
VISUAL STUDIO CODE (VSCODE)
4
10/1/23
10
5
10/1/23
11
12
6
10/1/23
13
1.
2.
14
7
10/1/23
Desktop
15
3.
16
8
10/1/23
17
18
9
10/1/23
19
20
10
10/1/23
21
Desktop
22
11
10/1/23
23
24
12
10/1/23
INTRODUCTION TO PYTHON
(EXERCISE)
25
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
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
4. Use the pop method to remove “model” from 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
31
THANK YOU
32
16