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.

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Python November 14, Unit 7. Python Hello world, in class.
Chapter 2: Input, Processing, and Output
Python Programming Chapter 2: Variables, expressions, and statements Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Chapter 2 Writing Simple Programs
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Guide to Programming with Python Chapter Two Basic data types, Variables, and Simple I/O: The Useless Trivia Program.
Computer Science 101 Introduction to Programming.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
Python Programming Fundamentals
Munster Programming Training
General Programming Introduction to Computing Science and Programming I.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Computer Science 101 Introduction to Programming.
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
Computer Science 101 Introduction to Programming.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
General Computer Science for Engineers CISC 106 Lecture 04 Dr. John Cavazos Computer and Information Sciences 09/10/2010.
1 C++ Programming Basics Chapter 2 Lecture CSIS 10A.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
CSC 107 – Programming For Science. Announcements  Memorization is not important, but…  … you will all still be responsible for information  Instead.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CSC 107 – Programming For Science. The Week’s Goal.
Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions.
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.
Variables, Expressions and Statements
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
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.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
9/29/99B-1 CSE / ENGR 142 Programming I Variables, Values, and Types © 1998 UW CSE.
Python Let’s get started!.
COMPUTER PROGRAMMING Year 9 – Unit 9.04 Week 3. Open the Python INTERPRETER Can you use the interpreter to solve these maths problems? 156 add
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
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.
Introduction to Python Lesson 2a Print and Types.
Agenda Introduction Computer Programs Python Variables Assignment
Topic: Python’s building blocks -> Variables, Values, and Types
Topics Designing a Program Input, Processing, and Output
Input and Output Upsorn Praphamontripong CS 1110
Python Let’s get started!.
Topic: Python’s building blocks -> Statements
Topic: Python’s building blocks -> Variables, Values, and Types
Revision Lecture
Variables, Expressions, and IO
Week 3 Computer Programming Learning Objective:
Chapter 2 Elementary Programming
Introduction to C++ Programming
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
Class 2.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
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.
Getting Started in Python
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

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 different instances of a problem, you can create an algorithm so the computer can solve the problem for you.

Review - What is Computer Science? An Algorithm  Step-by-step procedure to solve the problem from beginning (start state) to end (end state)  Sequential  Some steps can repeat  High level: only list important details

Values Fundamental building block in a programming language Values are the “things” that we save and manipulate There are only a few basic types of values …but we can make our own types of values

Data Types in Python Integers  whole numbers, positive or negative (5, 42, -7) Floats  Decimal numbers ( , ) Strings  sequences of characters (‘dog’, “cat”, ‘’’rat’’’, ‘17’, “23.5” ) classes and types are the same thing (for now) Can use one two or three quotes

Variables A way to name a place in memory for data Legal Names:  No spaces  Can’t start with a number start with letter or underscore  Can’t use keywords middle of "Variables, Expressions and Statements" chapter for list e.g., class, int  Don’t use symbols $, %, # illegal

Variables Takes a value, and assigns it a variable age = 18 #puts the int 18 into the variable age name = "Joe" #puts the string "Joe" into the variable name Can be reused  age = 87 changes the value in the variable age

Variables What’s currently in a variable  Interpreter: just type variable name and return  Program: use the print() function

Input Takes a string in from the keyboard  always a string, even if you enter a number temp = input() #gets a string and saves into variable temp

Input Problem: input always returns a string. What if we want to get a number?  age = input(“Enter your age”)  type(age) Must convert to the type we want int (string), float(string), str(int or float)

Debugging – finding errors / faults syntax errors runtime errors semantic errors

Comments Programs can get very long and convoluted. Sometimes we’d like to put in some words to explain what we’re doing python comments start with the # character.  everything on the line after the # is ignored

Practice Write a program that creates a variable for your name and a variable for your age, and prints a sentence like this:  Toby is 32

Practice Add code to calculate and print your age in decades:  That's 3.2 decades

Practice Get first name from the keyboard

Practice Get age from the keyboard