INPUT & VARIABLES.

Slides:



Advertisements
Similar presentations
CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
Advertisements

Python November 14, Unit 7. Python Hello world, in class.
Introduction to Python
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.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
Guide to Programming with Python Chapter Two Basic data types, Variables, and Simple I/O: The Useless Trivia Program.
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
Chapter 2: Variables, Operations, and Strings CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Introduction to Python
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Data Types Integer 15 StringHelloThere! Float/Real BooleanYes / No CharP.
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
Strings CS303E: Elements of Computers and Programming.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
How to start Visual Studio 2008 or 2010 (command-line program)
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.
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
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
Basics of Most C++ Programs // Programmer: Clayton Price date: 9/4/ // File: fahr2celc.cpp 03. // Purpose:
Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.
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.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
SEQUENCES:STRINGS,LISTS AND TUPLES. SEQUENCES Are items that are ordered sequentially and accessible via index offsets into its set of elements. Examples:
GCSE Computing: Programming GCSE Programming Remembering Python.
Simple “VICO” (“VIPO”) Programs (Variables, Input, Calculating or Processing, Output)
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
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.
Input, Output and Variables GCSE Computer Science – Python.
CS 106A, Lecture 4 Introduction to Java
C++ Basics Lecture 2.
Agenda Introduction Computer Programs Python Variables Assignment
Topics Designing a Program Input, Processing, and Output
Python: Experiencing IDLE, writing simple programs
Input and Output Upsorn Praphamontripong CS 1110
Lesson 1 - Sequencing.
Data Types and Conversions, Input from the Keyboard
Design & Technology Grade 7 Python
Presented By S.Yamuna AP/IT
Variables, Expressions, and IO
Introduction to C++ October 2, 2017.
Computational Thinking
Computational Thinking
What are variables? Using input()
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
What are variables? Using input()
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
What are variables? Using input()
Introduction to Python
Understanding Variables
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.
Errors.
Python Creating a calculator.
Presentation transcript:

INPUT & VARIABLES

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables Input - 1. The process of entering information into a computer. 2. The information entered or put into a computer for processing. CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables This is what you type in your PC : print "Halt!" s = raw_input("Who Goes there? ") print "You may pass,", s variable CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables When you ran the program, here is what your screen showed: OUTPUT : Halt! Who Goes there? Josh You may pass, Josh input CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables When you ran the program you probably noticed how you had to type in your name and then press Enter. Then the program printed out some more text and also your name. This is an example of input. CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables Variables are like a box that can store some piece of data. Next is a program to show examples of variables: Josh CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables SAMPLE PROGRAM 1 a = 123.4 b23 = ’Spam’ first_name = "Bill" b = 432 c = a + b print "a + b is", c print "first_name is", first_name print "Sorted Parts, After Midnight or",b23 OUTPUT : a + b is 555.4 first_name is Bill Sorted Parts, After Midnight or Spam CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables 123.4 Spam a b23 123.4 + 432 Bill 432 c first_name b CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables Strings are a sequence of letters, numbers and other characters. Example : Spam , Bill ,a + b is ,first_name is - string 123.4 , 432 - number CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables SAMPLE PROGRAM 2 a = 1 print a a = a + 1 a = a * 2 OUTPUT : 1 2 4 CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables a 2 X 2 = 4 1 a a 1 + 1 = 2 print a print a + 1 print a X 2 CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables SAMPLE PROGRAM 3 num = input("Type in a Number: ") str = raw_input("Type in a string:") print "num =", num print "num * 2 =",num*2 print "str =", str print "str * 2 =",str*2 OUTPUT : Type in a Number: 12.34 Type in a String: Hello num = 12.34 num * 2 = 24.68 str = Hello str * 2 = HelloHello CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables num variable gets data from input str variable gets data from raw_input If you want the user to type in a number use input because it returns a number If you want the user to type in a string use raw_input because it returns a string CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables Numbers are of type int or float (which are short for ’integer’ and ’floating point’ respectively) Strings are of type string Integers and floats can be worked on by mathematical functions, strings cannot. CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables SAMPLE PROGRAM 4 #This programs calculates rate and distance problems print "Input a rate and a distance" rate = input("Rate:") distance = input("Distance:") print "Time:",distance/rate OUTPUT : Input a rate and a distance Rate:5 Distance:10 Time: 2 CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables 5 rate distance 10 10 / 5 = 2 time = distance/rate CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables SAMPLE PROGRAM 4 (with error) #This programs calculates rate and distance problems print "Input a rate and a distance" rate = raw_input("Rate:") distance = input("Distance:") print "Time:",distance/rate string could not worked on by mathematical functions Note : raw_input uses to get data in string type CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables SAMPLE PROGRAM 5 #This program calculates the perimeter and area of a rectangle print "Calculate information about a rectangle" length = input("Length:") width = input("Width:") print "Area",length*width print "Perimeter",2*length+2*width OUTPUT : > python area.py Calculate information about a rectangle Length:4 Width:3 Area 12 Perimeter 14 CMPF 144-Fundamental of Computing Theory (Python)

CMPF 144-Fundamental of Computing Theory (Python) Input & Variables SAMPLE PROGRAM 6 #Converts Fahrenheit to Celsius temp = input("Farenheit temperature:") print (temp-32.0)*5.0/9.0 OUTPUT : > python temperature.py Farenheit temperature:32 0.0 Farenheit temperature:-40 -40.0 Farenheit temperature:212 100.0 CMPF 144-Fundamental of Computing Theory (Python)