Thinking about programming

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

Intro to Python Welcome to the Wonderful world of GIS programing!
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction to Python
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Data Types. Every program must deal with data The data is usually described as a certain type This type determines what you can do with the data and how.
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
Introduction to Python
Instructor: Craig Duckett Assignment 1 Due Lecture 5 by MIDNIGHT – NEXT – NEXT Tuesday, October 13 th I will double dog try to.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 6: Variables and constants.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #005 (April somthin, 2015)
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
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 When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Please log on The. AN INTRODUCTION TO ‘Python is a high-level, general purpose programming language’ Python is one of the many programming languages.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
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.
Python Let’s get started!.
Thinking about programming Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
Input, Output and Variables GCSE Computer Science – Python.
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
CS 100 Introduction to Computing Seminar September 12/14, 2016.
Chapter 1.2 Introduction to C++ Programming
Week 2 - Wednesday CS 121.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Python Let’s get started!.
Introduction to Python
Introduction to Computer Science / Procedural – 67130
Presented By S.Yamuna AP/IT
Formatting Output.
Type Conversion, Constants, and the String Object
Thinking about programming
Introduction to the C Language
More Nested Loops and Lab 5
Bools and simple if statements
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Types, Truth, and Expressions (Part 2)
Introduction to Primitive Data types
Coding Concepts (Data- Types)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Nested Looping
Introduction to Strings
Chapter 2: Introduction to C++.
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Thinking about programming
Variables and Computer Memory
Types, Truth, and Expressions
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
In your notebook… Purpose: What types of data can we store in C
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Primitive Data types
Types, Truth, and Expressions (Part 2)
Getting Started in Python
Presentation transcript:

Thinking about programming Intro to Computer Science CS1510 Dr. Sarah Diesburg

Last Time We used a design document to help us write code to solve a problem How much Olympic athletes win Each part of the design document can and should be used as comments in your program

Last Time We introduced constants Why would we want to use constants? Written in ALL_CAPS_STYLING Holds values that don’t change throughout your program Why would we want to use constants?

Variables and Types Python does not require you to pre-define the type of a variable What type a variable holds can change Unlike other programming languages… However, once a variable has a value it’s type matters a lot! Is x+3 legal? Thus proper naming is important!

Examples For example, you can’t use the + operator with a string and an int >>> “Sarah”+3 Python tries to convert one operand to the other operand’s type What about the + operator with a float and an int? >>> 4.1 + 3 >>> 3 + 4.1

Python “Types” integers: 5 floats: 1.2 Booleans: True (note the capital) Boolean named after Mathematician George Boole strings: “anything” or ‘something’ lists: [,]: [‘a’,1,1.3] others we will see

Use of quotation marks with String type Python allows the use of either Single quotes ‘This is a single quote sentence’ Double quotes “This is a double quote sentence” Triple quotes “”” These are most often used when writing comments that span over several lines.”””

What is a Type? A type in Python essentially defines two things: Internal structure of the data (what it contains) Kinds of operations you can perform Different methods are associated with different types of data >>> abc.capitalize() Method you can call on strings, but not integers Have you seen something like this before?

Converting Types A character ‘1’ is not an integer 1. We’ll see more on this later, but take my word for it. You need to convert the value returned by the input() command (characters) into an integer >>> inputString = “123” >>> inputInteger = int(inputString)

Type Conversion int(someVar) converts to an integer float(someVar) converts to a float str(someVar) converts to a string should check out what works: int(2.1)  2, int(‘2’)  2, but int(‘2.1’) fails float(2)  2.0, float(‘2.0’)  2.0, float(‘2’)  2.0, float(2.0)  2.0 str(2)  ‘2’, str(2.0)  ‘2.0’, str(‘a’)  ‘a’

Knowing the type type(variableName) Since the type of data stored in a variable can change, Python let’s us ask what the current type is: type(variableName)