La Salle University
College of Engineering and Architecture
ELC413b: Numerical Methods Laboratory
Activity No Score
01 Introduction to Python and Jupyter 30 points
I. Introduction
This lab uses Anaconda , a Python distribution with built
in packages such as numpy, matplotlib and sympy.
To install Anaconda, download the latest version from the
link below and follow the installation instructions.
https://www.anaconda.com/distribution/
Installing Anaconda also installs Jupyter. Jupyter is a
browser based IDE with interactive input and output.
Open Jupyter by clicking the icon similar to the one
below.
In this lab, try the following code examples to get you
started with Python and Jupyter.
II. Examples
1. Hello World
print("Hello, World!")
2. Arrays
>> cars = ["Ford", "Volvo", "BMW"]
>> x = cars[0]
>> x = len(cars)
3. Arithmetic
a= 21
b = 10
c = 0
c = a + b
print "Line 1 - Value of c is ", c
c = a - b
print "Line 2 - Value of c is ", c
c = a * b
print "Line 3 - Value of c is ", c
c = a / b
print "Line 4 - Value of c is ", c
c = a % b
print "Line 5 - Value of c is ", c
a = 2
b = 3
c = a**b
print "Line 6 - Value of c is ", c
a = 10
b = 5
c = a//b
print "Line 7 - Value of c is ", c
4. Conditonal Statements
If else
var1 = 100
if var1:
print "1 - Got a true expression value"
print var1
else:
print "1 - Got a false expression value"
print var1
var2 = 0
if var2:
print "2 - Got a true expression value"
print var2
else:
print "2 - Got a false expression value"
print var2
print "Good bye!"
5. Tuples
thistuple = ("apple", "banana", "cherry")
print(thistuple)
thistuple = ("apple", "banana", "cherry")
print(thistuple[1])
More tuorials available at
https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
III. Problems
1. Write a Python code that calculates the total
resistance of 3 resistors in parallel.
2. Write a python code that calculates the mean and
standard deviation of a given set of data.
3. Develop a simple python application to solve an
engineering problem.