1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

lOMoARcPSD|46679252

lOMoARcPSD|46679252

IT1815

Laboratory Exercise
Understanding Algorithm with Python
Objective:

At the end of the exercise, the students should be able to:

▪ Construct a Python script based on the given algorithms.

Software Requirement:

▪ Python 3.7 or higher

Procedure:

1. Study the following sample Python syntaxes:


Task Sample Syntax Remarks
Variable declaration x = 5 No need to indicate the
data type. Do not add
semi-colon.
Comment #This is a comment.
User input name = input(“Enter your name”)
Convert string to int(x) Convert to compare or
int or float. float(x) compute values.
Convert int or str(x) Convert if the output must
float to string. show a number and a
string.
Combine conditional x > 5 and x <10
statements. x > 5 or x < 10
not(x < 5)
if statement if x == 0: Use four (4) spaces per
print(“Enter a higherindentation level.
number”)
else-if statement elif x == 0:
print(“Enter a higher
number”)
else statement else:
print(“Try again”)
Create a list of items. my_list = [“red”, “blue”, Python recommends the
“green”] use of lists than arrays.
Display all items in a print(my_list)
list.
Create an empty list. my_list = []
Add an item to the end my_list.append(“yellow”)
of a list.
2. Open Notepad++.
3. Create a Python script that will compare two (2) numbers entered by the user. Refer to the sample
syntaxes and the algorithm below.
3.1. User enters the first number.
3.2. User enters the second number.
3.3. If the first number is less than, greater than, or equal the second number, a message is
displayed.
lOMoARcPSD|46679252

4. Save the script as algo1.py.


5. To test and run the script, open Command Prompt. Navigate to your file’s location then type
python algo1.py.

01 Laboratory Exercise 1 *Property of STI


Page 1 of 2

IT1815

6. Create another Python script that will display the names of your three (3) classmates. Refer to the
sample syntaxes and algorithm below.
6.1. User enters the name of the first classmate.
6.2. User enters the name of the second classmate.
6.3. User enters the name of the third classmate.
6.4. The name of the three (3) classmates are displayed.
7. Save the script as algo2.py.
8. Create a folder named LastName_FirstName_MI_LE1 (ex. Reyes_Nika_P_LE1) in your local drive.
9. Move the two (2) scripts to your folder.

GRADING RUBRIC (100 points):


Criterion Description Max Points
Correctness The code produces the expected result. 40
Logic The code meets the specifications of the problem. 40
Efficiency The code is concise without sacrificing correctness and logic. 10
Syntax The code adheres to the rules of the programming language. 10
TOTAL 100
lOMoARcPSD|46679252

01 Laboratory Exercise 1 *Property of STI


Page 2 of 2

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