Topic: Python’s building blocks -> Variables, Values, and Types

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Chapter 2: Input, Processing, and Output
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Computer Science 101 Introduction to Programming.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
CIS Computer Programming Logic
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Munster Programming Training
Computer Science 101 Introduction to Programming.
Sep 12, 2007Sprenkle - CS1111 Objectives Review  Linux  Why programming languages? Compiled vs. Interpreted Languages Programming in Python  Data types.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
King Saud University College of applied studies and community services CSC 1101 Computer Programming I Lecture 2.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Variables, Expressions and Statements
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Bill Tucker Austin Community College COSC 1315
Chapter # 2 Part 2 Programs And data
Fundamentals of Programming I Overview of Programming
Topic: Python Lists – Part 1
CMPT 120 Topic: Python’s building blocks -> More Statements
Agenda Introduction Computer Programs Python Variables Assignment
Topic: Introduction to Computing Science and Programming + Algorithm
Topic: File Input/Output (I/O)
Topic: Python’s building blocks -> Variables, Values, and Types
Topic: Recursion – Part 2
Topic: Functions – Part 1
Topic: Programming Languages and their Evolution + Intro to Scratch
Topic: Iterative Statements – Part 1 -> for loop
Topic: Introduction to Computing Science and Programming + Algorithm
Introduction to the C Language
BASIC ELEMENTS OF A COMPUTER PROGRAM
Topic: Python’s building blocks -> Statements
Topic: Conditional Statements – Part 1
Chapter 2: Input, Processing, and Output
CMPT 120 Topic: Functions – Part 4
Revision Lecture
CMPT 120 Topic: Python strings.
Topic: Functions – Part 2
Variables, Expressions, and IO
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Lecture2.
Computational Thinking
Computational Thinking
Chapter 2.
Introduction to the C Language
Introduction to the C Language
IDENTIFIERS CSC 111.
Programming Funamental slides
Variables ICS2O.
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
Programming Funamental slides
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Tutorial 10: Programming with javascript
Chapter 2: Input, Processing, and Output
Variables in C Topics Naming Variables Declaring Variables
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
CMPT 120 Lecture 4 – Unit 1 – Chatbots
Presentation transcript:

Topic: Python’s building blocks -> Variables, Values, and Types CMPT 120 Topic: Python’s building blocks -> Variables, Values, and Types

Learning outcomes At the end of this course, a student is expected to: Describe and apply fundamental concepts and terminology of Python: Literals Variables Data types Execution flow Create (design) small size programs using Python: Hand trace code (programs) and predict results of executing code (determining contents of variables and output)

Last Lecture Evolution of programming languages Compiled versus interpreted programming languages Introduced Python Illustrated the Software Development Process using Python Implement algorithm into computer program State problem Design algorithm + Identify data Test it

Today’s Menu Start learning Python’s building blocks Variables Values Types and Literal values Hand tracing Execution Flow i-clicker

In the real world, there are … “Things” e.g.: and Actions e.g.:

In the computer world, there are … Real World “Things” Actions Computer World “Things” -> Actions -> Scratch: -> Python: Data Variables (objects) Literal values Statements (or blocks) Operators Functions + methods

Input-Process-Output Model Most computer programs follow this model Input Process Output Data Data Data + Actions

Variable We saw in Lecture 3 that computers are very good at manipulating lot’s of data But in order for the computer to manipulate this data, we must tell the computer to remember the data We do this by using variables in our programs

Variable Definition: A variable is a memory location to which we give a name to which we assign a value of a particular data type In a computer program, variables are referred to by their name

Variable name Syntax rule: Can contain: Cannot contain: Must start with

Variable name Convention 1: use camelCase (see wikipedia) Example: finalLetterGrade Convention 2: user underscore between words Example: final_letter_grade Python is case sensitive: variable PRICE variable Price variable price 3 different variables

Value and their data type A value can either be an integral (whole) number Example: in Python, this data type is called: int (integer) a floating point number in Python, this data type is called: float a sequence of character(s) in Python, this data type is called: str (string)

Variable – Demo How to create a variable in Python In doing so, we shall introduce the Assignment operator “=“ (assignment statement) How to use a variable In doing so, we shall introduce the output built-in function ”print” (output statement) How to assign another value to an already existing variable In doing so, we shall use the Assignment operator “=“ (assignment statement) Using Python IDLE Interpreter Shell & Program Editor

Weakly Typed Python is a weakly typed high level programming language This means that when we need to use a variable in our Python program, all we need to do is assign a value to our variable in order to create the variable (or the space in memory)

Strongly Typed Example: in C This is not the case in strongly typed high level programming languages like C, C++ and Java, where a variable must first be declared, i.e., one must first state the type of value this variable is to reference, before the variable is used Example: in C float radius; <- variable declaration float areaCircle; <- variable declaration float pi; <- variable declaration pi = 3.14; <- variable initialized radius = 2.5; <- variable initialized // area of circle = pi * radius2 <- comment areaCircle = pi * pow(radius,2)<- variables used

Literal Value Examples: The values in red are literal values: apple = 0.75 juice = 1.65 sandwich = 4.80 They are called “literal values” because they are literally typed into a program

GPS (Good Programming Style) – 1 Variable name must be descriptive, i.e., it must describe the purpose of the variable or the meaning of its value For example: Why? Creates self-documented code

It follows that … Reusing variable for different purposes is never a good idea! For example: Why?

GPS (Good Programming Style) – 2 We cannot use a Python keyword as a variable name Python keywords: Section 2.2 (page 10) of our online textbook For example: Why?

GPS (Good Programming Style) – 3 Have a look at our Good Programming Style web page and see what it says about Literal Values

Summary Started learning Python’s building blocks Variables Values Types and Literal values Hand tracing Execution Flow i-clicker

Next Lecture Continue learning Python’s building blocks -> statements Categories of Statements Assignment statement Input statement Output statement Operational statement