Introduction to Python Lesson 2a Print and Types.

Slides:



Advertisements
Similar presentations
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Advertisements

Programming in python Lesson 2.
Python November 14, Unit 7. Python Hello world, in class.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
Introduction to Computers and Programming - Class 2 1 Introduction to Computers and Programming Class 2 Introduction to C Professor Avi Rosenfeld.
Introduction to Python
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏
Basic Input/Output and Variables Ethan Cerami New York
* Note: All of the material for the Required Textbook, Optional Textbook are protected by Copyright Law. * Professor Sana Odeh’s notes and programs listed.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Chapter 2: Variables, Operations, and Strings CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
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.
INTRODUCTION TO PYTHON. 1. The 5 operators in Python are: + - * / %
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
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.
Maths in Python [ slide 5 ] 1.Copy the table 2.Race a friend with a calculator to see whether Python is faster than a calculator: a) 5 * 6.5 = b)7 / 3.
Variables, Expressions and Statements
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏ Sec 9-7 Web Design.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Chapter 2 Variables.
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.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Cosc175/operators1 Algorithms computer as the tool process – algorithm –Arithmetic: addition,subtraction,multiplication,division –Save information for.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
CS Jan 2007 Chapter 2 sections 1, 2, 4 – 6, 8,
1 Variables and Arithmetic Operators in JavaScript.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
Data Manipulation Variables, Data Types & Math. Aug Variables A variable is a name (identifier) that points to a value. They are useful to store.
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
JavaScript Variables. Definition A variable is a "container" for information you want to store. A variable's value can change during the script.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
Input, Output and Variables GCSE Computer Science – Python.
Chapter 2 Variables.
Chapter 6 JavaScript: Introduction to Scripting
Python: Experiencing IDLE, writing simple programs
Variables and Expressions
Documentation Need to have documentation in all programs
Computing Fundamentals
Design & Technology Grade 7 Python
Variables, Expressions, and IO
Introduction to C++ Programming
Learning Outcomes –Lesson 4
Unit-1 Introduction to Java
Manipulating Text In today’s lesson we will look at:
Chapter 2 Variables.
“If you can’t write it down in English, you can’t code it.”
Variables and Expressions
Variables, Data Types & Math
Variables, Data Types & Math
Variables, Data Types & Math
Unit 3: Variables in Java
Chapter 2 Variables.
Understanding Variables
Presentation transcript:

Introduction to Python Lesson 2a Print and Types

Learning Outcomes In this lesson the students will: 1.Print a message that contains text, numbers and calculations 2.Create variables with proper names 3.Perform calculations using addition, subtraction and multiplication

More on printing: print() print() can print text in quotes, numbers and calculations separated by commas For example: print(“1+2 = ”, 1+2) 1+2 = 3

Variables and values A variable is a named piece of memory that stores a value To create a variable in Python: – write the name of the variable and assign it a value num_1 = 10 = means assignment (store the value on the right in the variable on the left)

Example So what if I wanted to create another variable to store the value 7 and print it to the screen? Let’s do it in IDLE together

Sample code num_1=7 print(num_1)# Easy print example print(“The value is ”, num_1) # better example

Naming variables Must begin with a letter (a - z, A - Z) or underscore (_) Remaining characters can be letters, numbers or _ Case Sensitive Can be any (reasonable) length Can’t be a keyword The following is recommended: – Always start a variable name with a lowercase letter. – Use underscores to separate words. – Use meaningful names

Valid names My_var my_var $_123 number! thisIsAVARiableDoYOuLikeIT print

Kinds of values Python allows us to store different types of values (data types or classes). For example: Integers: whole numbers e.g. 5, 899, 12 Strings: A string is a sequence of one or more characters. – Strings start and end with quote " or apostrophe ' characters. name = " Hello " str1= " This is a string " str2 = " This is a really really really long string! "

Example Write a program that creates two Strings. The first String should store your first name and the second string should store your surname. Print your full name to the screen on a single line. Write a program that has two integer variables, one with the value 100 and the other with the value 15. Print out the values in the variables.

Sample Code first_name = “John” surname=“Doe” print(first_name, surname) ____________________________________________ num_1 = 100 num_2 = 15 print(num_1, num_2)# better with a message

Operations and Expressions OperatorSymbolExpressions (using integers) Answer Addition Subtraction Multiplication*10*330 Division (integer)//10//33 (floats)/10.0/3.0Division3.0 Modulus (integer) %10%31

Example Write a program that creates two integer variables, gives them values and then prints the sum of the variables to the screen.

Sample Code num_1 = 10 num_2 = 20 print(num_1,“+”, num_2, “=”, num_1+num_2)

Lesson Review In this lesson …