0% found this document useful (0 votes)
21 views4 pages

Lab 1

Uploaded by

CALLIE XI
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)
21 views4 pages

Lab 1

Uploaded by

CALLIE XI
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/ 4

De La Salle University - Dasmariñas

COLLEGE OF INFORMATION AND COMPUTER STUDIES


COMPUTER SCIENCE DEPARTMENT

LABORATORY ACTIVITY 1 - REVIEW OF PROGRAMMING ENVIRONMENT: PYTHON


Objectives

1. Present Python programming as the programming platform for the entire course.
2. To review the Python programming environment and basic syntax in variables and
operators, creating lists and arrays, functions, and plotting.

Rationale

This laboratory activity aims to assist the student to review the basic syntax in Python
programming. The knowledge in Python programming will enable the students to solve
succeeding laboratory activities.

Background

Python is a very popular high-level general-purpose programming language. As an


interpreted language, code does not need to be compiled and can be run on any system where
an interpreter is available. The core language is Free and Open-Source Software (FOSS) and can
be acquired and used at no cost. There is a very large library of routines available, including ones
specifically designed for scientific computing, such as SciPy or NumPy.

The Spyder Interface

The Spyder IDE is already included in the Anaconda installation.

If you are not using Anaconda, you can find Spyder and installation instructions at
https://www.spyder-ide.org/

To launch Spyder, you can select it from the list of programs for your computer or you can run
Spyder in a terminal or command window.

When you start Spyder, you should see an interface with multiple panes as shown in Figure
below.
Pre-task

Using any Python editor, try the following mathematical expression to determine the answer.

Example:

Using the Python editor, here is the statement that should be typed, ((2+3)*7), then press
<enter> to see the result. The answer is equal to 35.

Machine Problem

Convert the following equations into valid Python commands and submit both the screenshot
of the input and output of the command from the console. (40 total points)

1. Basic Arithmetic (10 pts.) Results:


2. Creating and Editing Matrices (10pts.)
Results:

3. Create the array [3 6 2 9 12] and replace the second element with the value in that
location cubed. That is, cube the value found in that location and store it back in the same
location. (10 pts.)
Results:

4. Plotting in Python. (10 pts.)


There is a Python library available called matplotlib that provides 2D-plotting tools and
functions. It is included in the Anaconda installation, and it can be loaded into Python
using the import command. We will be importing the library as plt to be consistent with
the available documentation for matplotlib.

import matplotlib.pyplot as plt

The basic 2D plot command plt.plot(x, y)

where x and y are any vector names.

Line specifiers—an optional parameter to the plot function—can be used to control the
color of the line, the style of the line, and any data markers.
Plot the data in the following table to explore line specifiers and submit both the input
and output of the command from the interpreter.

Results: (should include the plot output)

Rubrics

Level of Achievement

Criteria Excellent Good Needs Poor


Improvement

Correctness – the 100% (50) 80% (40) 60% (30) 40% (20)
program is syntactically
and logically correct
(50%)

Completeness -covers all 100% (50) 80% (40) 60% (30) 40% (20)
the required input,
process and output (50%)

Reference: Gordon, S. I., & Guilfoos, B. (2017). Introduction to Modeling and Simulation with
MATLAB® and Python. Chapman and Hall/CRC.

You might also like