0% found this document useful (0 votes)
2 views30 pages

Lecture 1

The document outlines the syllabus for EECE 1315, focusing on data structures and programming, with assessments including tests, quizzes, and a final exam. It introduces Python programming, covering the setup of the programming environment, variables, data types, and basic operations. The document emphasizes the importance of using descriptive variable names and understanding data types such as strings, integers, and floats.
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)
2 views30 pages

Lecture 1

The document outlines the syllabus for EECE 1315, focusing on data structures and programming, with assessments including tests, quizzes, and a final exam. It introduces Python programming, covering the setup of the programming environment, variables, data types, and basic operations. The document emphasizes the importance of using descriptive variable names and understanding data types such as strings, integers, and floats.
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/ 30

EECE 1315

DATA STRUCTURE AND


PROGRAMMING
Lesson 1

INTRODUCTION
A S S O C . P R O F. D R . R A S H I D A H F U N K E O L A N R E W A J U
ASSESSMENT
DISTRIBUTION
SEM 2 2023/2024 SECT 1 & SECT 2( 10-11.20am, 2-3.20pm)

Assessment Methods Percentage Dates


Summative Assessment 40 Test 1 – Week 6 (15%)
Test 2 – Week 11 (15%)
Quiz 1 - (5%)
Quiz 2 - (5%)
Project 10 Submission – Week 12

Must-pass Assessment Method(s) Percentage


Final Exam 50 Objectives (Python) – 20
Subjective (Data Structures)
– 60
Programming (Python Class)
– 20
Total 100
Getting Started
Setting Up
Your • FIRST HALF OF THE SEMESTER:
• PYTHON PROGRAMMING
Programming
• MIDTERM : PYTHON PROGRAMMING
Environment
PYTHON INTERPRETER • SECOND HALF OF THE SEMESTER:
• DATA STRUCTURE (ALGORITHM)

• FINAL: PYTHON PROGRAMMING &


DATA STRUCTURE
Python - IDLE
IDLE (Integrated Development and

Python - IDLE
Learning Environment) is an
integrated development environment
(IDE) for Python. The Python
installer for Windows contains the
IDLE module by default .
I D L E i s n o t a va i l a b l e by d e fa u l t i n
Python distributions for Linux. It
needs to be installed using the
respective package managers.
Execute the following command to
install IDLE on Ubuntu:
$ sudo apt-get install idle

IDLE can be used to execute a single statement just like Python Shell and also to
create, modify, and execute Python scripts. IDLE provides a fully-featured text
editor to create Python script that includes features like syntax highlighting,
autocompletion, and smart indent. It also has a debugger with stepping and
breakpoints features.

To start an IDLE interactive shell, search for the IDLE icon in the start menu and
double click on it.
Variables and Simple
Data Types
Python Variables and Data Types
What Really Happens When You Run hello_world.py

Let’s take a closer look at what Python does when you run
hello_world.py.
As it turns out, Python does a fair amount of work, even
when it runs a simple program:

In this section, you’ll learn


about the different kinds of
data you can work with
within your Python
programs.
You’ll also learn how to use
variables to represent data in
your programs.
VARIABLES What Really Happens When You Run hello_world.py
Let’s try using a variable in hello_world.py.
Add a new line at the beginning of the file and modify the
second line.

We’ve added a variable


named message.
Every variable is connected
to a value, which is the
information associated with
that variable.
In this case the value is the
"Hello Python world!" text.
Variable names can contain only letters,
numbers, and underscores. They can start
with a letter or an underscore, but not with a
number. For instance, you can call a variable
message_1 but not 1_message.

Spaces are not allowed in variable names, but


VARIABLES underscores can be used to separate words in
variable names. For example,
greeting_message works, but greeting
NA M I NG A ND U S I NG VA R I A BL E S message will cause errors.

Avoid using Python keywords and function


names as variable names; that is, do not use
When you’re using variables in words that Python has reserved for a
Python, you need to adhere to a few particular programmatic purpose, such as the
rules and guidelines. word print.

Breaking some of these rules will Variable names should be short but
descriptive. For example, name is better than
cause errors; other guidelines just n, student_name is better than s_n, and
help you write code that’s easier to name_length is better than
read and understand. length_of_persons_name.

Be sure to keep the following variable Be careful when using the lowercase letter l
rules in mind: and the uppercase letter O because they
could be confused with the numbers 1 and 0.
VARIABLES Avoiding Name Errors When Using Variables
We’ll write some code that generates an error on purpose.
Enter the following code, including the misspelt word
mesage shown in bold:

Every programmer makes


mistakes, and most make
mistakes every day.
Although good programmers
might create errors, they also
know how to respond to those
errors efficiently.
Let’s look at an error you’re
likely to make early on and
learn how to fix it.
VARIABLES Variables are labels
In class:
1. Simple Message: Assign a message to a
variable, and then print that message.
2. Simple Messages: Assign a message to a
variable and print that message. Then change
the value of the variable to a new message
and print the new message.
DATA TYPES: A string is a series of characters.

STRINGS Anything inside quotes is considered a string in Python,


and you can use single or double quotes around your
strings like this:
"This is a string."
'This is also a string.'

Because most programs define


and gather some sort of data,
then do something useful with
it, it helps classify different
data types.
The first data type we’ll look at
is the string.
Strings are quite simple at first
glance, but you can use them
in many ways.
Changing Case in a String with Methods
One of the simplest tasks you can do with strings is to
DATA TYPES: change the case of the words in a string.

STRINGS Look at the following code, and try to determine what’s


happening:

In this example, the variable MyName refers to the


string “Rashidah Funke Olanrewaju".
The method title() appears after the variable in the
print() call.
A method is an action that Python can perform on a
piece of data.
Using Variables in Strings

In some situations, you’ll want to use a variable’s value inside a string.

DATA TYPES: For example, you might want two variables to represent a first name and
a last name respectively, and then want to combine those values to
display someone’s full name:
STRINGS

To insert a variable’s value into a string, place


the letter f immediately before the opening
quotation mark.
Put braces around the name or names of any
variable you want to use inside the string.
Adding Whitespace to Strings with Tabs or Newlines

In programming, whitespace refers to any nonprinting character, such as


DATA TYPES: spaces, tabs, and end-of-line symbols.
To add a tab to your text, use the character combination \t
STRINGS To add a newline in a string, use the character combination \n:

You can also combine tabs and


newlines in a single string.
The string "\n\t" tells Python to
move to a new line, and start the
next line with a tab.
Avoiding Syntax Errors with Strings

One kind of error that you might see with some regularity is a syntax
error.
DATA TYPES: A syntax error occurs when Python doesn’t recognize a section of your

STRINGS program as valid Python code.

For example, if you use an apostrophe within


single quotes, you’ll produce an error.
This happens because Python interprets
everything between the first single quote
and the apostrophe as a string.
STRINGS
In class:
1. Personal Message: Use a variable to
represent a person’s name and print a
message to that person. Your message should
be simple, such as, “Hello Aina, would you
like to learn some Python today?”
2. Name Cases: Use a variable to represent a
person’s name, and then print that person’s
name in lowercase, uppercase, and title case.
Integers

You can add (+), subtract (-), multiply (*), and divide (/)
DATA TYPES: integers in Python.

NUMBERS Python supports the order of operations too, so you can


use multiple operations in one expression.

Numbers are used quite often


in programming to keep score
in games, represent data in
visualizations, store information
in web applications, and so on.
Floats

Python calls any number with a decimal point a float.

DATA TYPES: This term is used in most programming languages, and it refers
to the fact that a decimal point can appear at any position in a
NUMBERS number.

Every programming language must be


carefully designed to properly manage
decimal numbers so numbers behave
appropriately no matter where the decimal
point appears.
Integers and Floats

When you divide any two numbers, even if they are integers that
result in a whole number, you’ll always get a float.
DATA TYPES: If you mix an integer and a float in any other operation, you’ll
NUMBERS get a float as well

Python defaults to a float in any


operation that uses a float, even if the
output is a whole number.
Underscores in Numbers

When you’re writing long numbers, you can group digits using
DATA TYPES: underscores to make large numbers more readable.

NUMBERS When you print a number that was defined using underscores, Python
prints only the digits.

Python ignores the underscores when storing


these kinds of values.
Even if you don’t group the digits in threes, the
value will still be unaffected.
To Python, 1000 is the same as 1_000, which is
the same as 10_00.
Multiple Assignments

You can assign values to more than one variable using just a
DATA TYPES: single line.

NUMBERS This can help shorten your programs and make them easier to
read; you’ll use this technique most often when initializing a set
of numbers.

You need to separate the variable names


with commas, and do the same with the
values, and Python will assign each value to
its respectively positioned variable.
Constants

A constant is like a variable whose value stays the same


DATA TYPES: throughout the life of a program.
Python doesn’t have built-in constant types, but Python
NUMBERS programmers use all capital letters to indicate a variable should
be treated as a constant and never be changed

When you want to treat a variable as


a constant in your code, make the
name of the variable all capital letters.
NUMBERS
In class:
Number Eight: Write addition, subtraction,
multiplication, and division operations that each
result in the number 8. Be sure to enclose your
operations in print() calls to see the results. You
should create four lines that look like this:
print(5+3)
Your output should simply be four lines with the
number 8 appearing once on each line.
How Do You Write Comments?

In Python, the hash mark (#) indicates a comment.


DATA TYPES: Anything following a hash mark in your code is ignored by the

COMMENTS Python interpreter.


For example:

Comments are an extremely useful


feature in most programming
languages.
Everything you’ve written in your
programs so far is Python code.
COMMENTS
In class:
Adding Comments: Choose two of the
programs you’ve written and add at least
one comment to each.
If you don’t have anything specific to write
because your programs are too simple at
this point, just add your name and the
current date at the top of each program file.
Then write one sentence describing what
the program does.
Learned to work with variables

Learned to use descriptive variable names and


how to resolve name errors and syntax errors
when they arise

Learned what strings are and how to display


strings using lowercase, uppercase, and title
case

Summary Using whitespace to organize output neatly,


and learned to strip unneeded whitespace
from different parts of a string

Working with integers and floats, and


learned some of the ways you can work
with numerical data
The bigger picture

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