Data Types Integer 15 StringHelloThere! Float/Real15.625 BooleanYes / No CharP.

Slides:



Advertisements
Similar presentations
EasyGUI “Probably the Easiest GUI in the world”. Assumptions (Teachers’ Notes) This resources sets out an introduction to using easyGUI and Python
Advertisements

Computer Programming w/ Eng. Applications
Programming Patterns CSC 161: The Art of Programming Prof. Henry Kautz 9/30/2009.
Self Check 1.Which are the most commonly used number types in Java? 2.Suppose x is a double. When does the cast (long) x yield a different result from.
Intro to Python Welcome to the Wonderful world of GIS programing!
COMPSCI 101 Principles of Programming Lecture 6 – Getting user input, converting between types, generating random numbers.
Objective: Dealing with data in C++ Agenda: Notes Essay Help.
Intro to Python. Python is an interpreted language Can be used interactively Identifiers are case-sensitive Operators: + - * / ** Arbitrarily large integer.
Python November 14, Unit 7. Python Hello world, in class.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
Introduction to Python
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
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.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
Input, Output, and Processing
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
Introduction to Pascal The Basics of Program writing.
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.
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.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Please log on The. AN INTRODUCTION TO ‘Python is a high-level, general purpose programming language’ Python is one of the many programming languages.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
INPUT & VARIABLES.
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.
Variables, Input, and Output. Challenge: ● Ask the user his or her name, and repeat that name to the user ● Pause video and try.
The ‘while’ loop ‘round and ‘round we go.
Variables, Types, Expressions Intro2CS – week 1b 1.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Exception Handling and String Manipulation. Exceptions An exception is an error that causes a program to halt while it’s running In other words, it something.
GCSE Computing: Programming GCSE Programming Remembering Python.
InterestRate Create an InterestRate class and InterestRateViewer client class to do the following: A person is purchasing an item with their credit card.
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
SEQUENCES:STRINGS,LISTS AND TUPLES. SEQUENCES Are items that are ordered sequentially and accessible via index offsets into its set of elements. Examples:
Course A201: Introduction to Programming 09/09/2010.
Introduction to Python Lesson 2a Print and Types.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
Input, Output and Variables GCSE Computer Science – Python.
Math, Data Types. Python Math Operations OperationOperator Addition + Subtraction – Multiplication * Division (floating point) / Division (integer) //
Input and Output Upsorn Praphamontripong CS 1110
Data Types and Conversions, Input from the Keyboard
Formatting Output.
Introduction to Python and programming
Design & Technology Grade 7 Python
Variables, Expressions, and IO
Formatting Output.
Computational Thinking
Computational Thinking
What are variables? Using input()
Introduction to Python and programming
Introduction to Python and programming
Reading Input from the Keyboard
Introduction to Python and programming
Reference semantics, variables and names
Python Basics with Jupyter Notebook
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.
DATA TYPES AND OPERATIONS
CS 1111 Introduction to Programming Spring 2019
Introduction to Python and programming
Introduction to Python
Presentation transcript:

Data Types Integer 15 StringHelloThere! Float/Real BooleanYes / No CharP

Strings Greeting = ‘Hello World’ print (Greeting) Hello World Letter = Greeting[2] print (Letter) l

Strings Len Function Name = ‘Dave’ len(Name) 4 Use to find out length of string

Strings converting data types 23 #an integer Str(value) will convert a given value to a string. Str(23) # is now a string ‘23’ e.g.1. Age as an ordinary integer. Age = 15 print(Age – 2) 13 e.g.2. Age converted to a string Age = 15 print(str(Age) – 2) ERROR ! # can’t take a number value away from a string! To convert from one data type to another, python has some useful functions

Strings converting data types e.g.4. Concatenate a string and integer Age = 15 Statement= ‘You are’ Statement + Age ERROR!!! …try Statement + str(Age) Statement15 Or better still Statement + ‘ ‘ + str(Age) You are 15

converting data types We can also try converting to integer data type Age = ’99’ type(Age) …try Type(int(age)) Obviously, you can’t convert ALL data to type integer! e.g Greeting = ‘Hello World’ Type(int(Greeting)) Error!!! #letters don’t correlate to a number!

converting data types We can also try converting to integer data type to a Floating data type (i.e. a REAL number) Age = 99 type(Age) …try NewAge = float(Age) Print(NewAge) 99.0 e.g. Pi = 3.14 type(Pi)

Prompting User for some Data We will use input() to grab some data from our end user. Age = input(‘What is your Age? ’) print(Age) ’99’ # note…this is a string Converting this into an integer can be done by…? Age = int(input(‘What is your Age? ’)) print(Age) 99 # note…this is a now an integer

Prompting User for some Data TASK Prompt the user for 5 numbers. Each number should be assigned an appropriate Variable name e.g. Num1, Num2 etc After 5numbers have been entered, the sum of the numbers should be outputted as ‘The sum of your 5 numbers is x’ The final line should show the average of the 5 numbers, and should read like this ‘The average of your 5 numbers is x’ ((Think carefully about which data types to use in the Sum and Average calculations))