Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.

Slides:



Advertisements
Similar presentations
Python Basics: Statements Expressions Loops Strings Functions.
Advertisements

Types and Arithmetic Operators
Introduction to C Programming
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
Introduction to Python
Chapter 2 Writing Simple Programs
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 2: Introduction to C++.
JavaScript, Third Edition
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
A First Book of ANSI C Fourth Edition
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Programming.
Introduction to Python
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
2440: 211 Interactive Web Programming Expressions & Operators.
Input, Output, and Processing
Course websites CS201 page link at my website: Lecture slides Assistant’s Information Recitations Office Hours Make-up.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Introduction to Programming with RAPTOR
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
C++ for Engineers and Scientists Second Edition
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
JavaScript Variables Like other programming languages, JavaScript variables are a container that contains a value - a value that can be changed/fixed.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Chapter 2 Writing Simple Programs
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 6 JavaScript: Introduction to Scripting
Python: Experiencing IDLE, writing simple programs
Input and Output Upsorn Praphamontripong CS 1110
BASIC ELEMENTS OF A COMPUTER PROGRAM
Basic Elements of C++.
Data Types, Identifiers, and Expressions
Variables, Expressions, and IO
Section 3.2c Strings and Method Signatures
Basic Elements of C++ Chapter 2.
Data Types, Identifiers, and Expressions
INPUT & OUTPUT scanf & printf.
Introduction to C++ Programming
T. Jumana Abu Shmais – AOU - Riyadh
Variables, Identifiers, Assignments, Input/Output
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
ICT Programming Lesson 4:
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Presentation transcript:

Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1

Computing and Memory All computing in terms of memory locations – Storing values into locations in memory – Reading values from locations in memory Example: Converting Celsius temperature to Fahrenheit 1.Get Celsius temp from user, store in location 1 2.Compute 1.8 x value in location 1, add 32, store in location 2 3.Output value in location 2 to user

Variables Variable  name given to location in memory Example: Converting Celsius temperature to Fahrenheit 1.Get Celsius temp from user, store in celsius_temperature 2.Compute 1.8 x celsius_temperature + 32, store in fahrenheit_temperature 3.Output value of fahrenheit_temperature to user

Namespaces Python environment / operating system maps variables to locations in memory Namespace: list of variables and corresponding values currently active in Python environment – Variable added to namespace when first used – Other languages require variable to be declared first – Can use id(variable) function to find actual numeric id Python uses for variable

Naming Variables Rules (different in other languages) – Must start with letter or underscore – Rest may contain letters, underscores, and digits – Cannot contain spaces or other characters – Case sensitive – Cannot be Python keyword Should be descriptive (readability)

Assignment Storing values into variables Syntax: variable = expression – Expression evaluates to a value – That value stored in the variable – Not same as = in math! x = 7 assigns the value 7 to x 7 = x not legal!

Expressions Expressions (on RHS of assignment) may contain: – Literals (fixed values) Numbers 2, 3.5, -12.6, etc. Strings (must be inside quotes)“John” BooleansTrue, False – Variables Must have already been assigned a value! – Functions Must return a value

Functions Predefined code with action based on list of arguments Syntax: functionname(list of arguments) – multiple arguments separated by commas – May return a value (so can be part of expression) Examples: – print(list of strings) Displays strings separated by spaces – input(prompt)Displays prompt, returns value entered by user – id(variable) Returns numeric id of variable in namespace

Expressions and Operators Variables, literals, functions can be combined using operators Most are binary operators combining 2 operands – Exception: unary minus sign-12 Syntax: operand operator operand Example: Can append two strings using + string3 = string1 + string2

Example # Prompt the user for their first and last name first_name = input(“What is your first name? ”) last_name = input(“What is your last name? ”) # Combine the two into a full name # (separated by a space) full_name = first_name + “ “ + last_name # Display greeting to user with their full name print(“Hello”, full_name)