ECE PE5: Instrumentation & Control Track "Computer Vision System With Applied Robotics"
ECE PE5: Instrumentation & Control Track "Computer Vision System With Applied Robotics"
1. Python Programming
Overall Grade:
Midterm Grade = 50%MG(lec) + 50%MG(lab)
Final Grade = 50%FG(lec) + 50%FG(lab)
Examination
Project
Midterm Project: Image Processing using Python
Final Project: Computer Vision Robot System
Policy / Rules
Tardiness:
3 Lates = 1 Absent
Max. Allowable Absences = 3
https://en.wikipedia.org/wiki/Python_(programming_language)
What is
Python?
Why use
Python?
What can I
build with
Python?
Fundamentals of Python
Programming Language
Output Statement:
print function
print displays output to your console
print('Hello world')
Hello world
Enclose strings in single or double quotes
print('Hello world single quotes')
print("Hello world double quotes")
Hello world
Hello World
Hi Cebu
Hi & Hello CIT-U ECE Students
Welcome to Python Programming
Debugging with print
print('Adding numbers')
x = 42 + 206
print('Performing division')
y = x / 0
print('Math complete')
Adding numbers
Performing division
Traceback (most recent call last):
File "demo.py", line 4, in <module>
y = x / 0
ZeroDivisionError: float division by zero
Comment
We add comments to our code using #
# This is a comment in my code it does nothing
Lines that start with # are not executed
# This is a comment in my code it does nothing
# print('Hello world')
# print("Hello world")
# No output will be displayed!
Comment calls to other programs to explain
their purpose
# Enable PIN check as listed in
# security requirements
enable_pin(current_user, pin)
Comments document your code so you and
other programmers can understand the code
# Using double quotes for this string because
# the string itself contains a single quote
print("It's a small world after all")
print('Hello world')
# print('It's a small world after all')
Hello world
Variables
Making variables
# declaration of variable in python
x = 10 # x is an integer
y = 2.5 # y is a floating point variable
str_1 = 'Welcome' # str_1 is a string variable
boolean_a = True # boolean_a is a Boolean variable
Input Statement:
input function
Getting information from the user
name = input('Please enter your name: ')
print(name)
# compound assignment
x += 10 # x = x + 10
y -= 5 # y = y – 5
z /= 2 # z = z / 2
a *= 3 # a = a * 3
Strings
String
Example:
string2 = ‘I am a string’
String indexing
Let:
s = ‘Hello Python’
Substring
# example of extracting a portion in a string
string1 = ‘Hello Python’
print(string1[0])
print(string1[len(string1)-1])
print(string1[-2])
print(string1[0:3])
H
n
o
Hel
Concatenating & Repeating Strings
# Strings can be added together with plus(+)
# operator
str1 = ‘Welcome’
str2 = ‘ ECE’
print(str1 + str2)
print(‘*^’*5)
Welcome ECE
*^*^*^*^*^
You can use functions to modify strings
sentence = 'The dog is named Sammy'
print(sentence.upper())
print(sentence.lower())
print(sentence.capitalize())
print(sentence.count('a'))
Thank you