Getting Input in Python Assumes assignment statement, typecasts.

Slides:



Advertisements
Similar presentations
User Input. Why user entry? When we assign values (age = 16), we are making a program static…it never changes. If we ask the user to enter the values,
Advertisements

Computer Science 2 Data Structures V section 2 Recitation 1.
1 Loops. 2 Often we want to execute a block of code multiple times. Something is always different each time through the block. Typically a variable is.
Chapter 3 Assignment and Interactive Input. 2 Objectives You should be able to describe: Assignment Operators Mathematical Library Functions Interactive.
Computer Science 1620 Variables and Memory. Review Examples: write a program that calculates and displays the average of the numbers 45, 69, and 106.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
ES 100: Lecture 7 String Functions 1.Log in 2.Open MATLAB 3.Change the current directory and path to U: 4.Change the numeric display to compact (File,
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Basic Input/Output and Variables Ethan Cerami New York
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
Python Programming Fundamentals
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Computer Science 111 Fundamentals of Programming I Basic Program Elements.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Input, Output, and Processing
Sept 18, 2007Sprenkle - CS111 Lab 0 Feedback Great! Great! Details got some of you Details got some of you  Print out copy  Copy directory to turnin.
S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: User Input / Output Programming Environment.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Input / Output Input – reads/gets data for the program Output – the product, after processing Both can be: interactive I/O (while program is running)
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.
JavaScript III Functions and Abstraction. 2 JavaScript so far statements assignment function calls data types numeric string boolean expressions variables.
Variables, Expressions and Statements
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
Lesson 4 Input. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are using. The reason it is not.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Printing in Python. Printing Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external.
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,
29 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Introduction to Programming
Slides prepared by Rose Williams, Binghamton University Console Input and Output.
Primitive Data Types int is a primitive data type A primitive data type is one that stores only a single piece of data. TypeStorageDescription int 4 bytes+ve.
CSD 340 (Blum)1 Introducing Text Input elements and Ifs.
CSx 4091 – Python Programming Spring 2013 Lecture L2 – Introduction to Python Page 1 Help: To get help, type in the following in the interpreter: Welcome.
CS 115 Lecture 7 Graphics – coordinate systems, Text, Entry, aliases Taken from notes by Dr. Neil Moore.
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
1 Input (Read) Statement. Variable Declaration (Definition) Initialization Assignment Displaying variables: using cout statement Reading variables from.
ME 120: Arduino Programming Arduino Programming Part II ME 120 Mechanical and Materials Engineering Portland State University
Introduction to Programming
Fundamentals of Programming I Overview of Programming
Input and Output Upsorn Praphamontripong CS 1110
Data Types and Conversions, Input from the Keyboard
Arduino Programming Part II
Introduction to Programming
Introduction to Programming
Keyboard Input and Screen Display ––––––––––– Interactive Programming
getline() function with companion ignore()
Review.
Imperative Programming
Lists in Python.
Introduction to Programming
Python 19 Mr. Husch.
Python Basics with Jupyter Notebook
Introduction to Programming
Python 10 Mr. Husch.
Module 5 ● Vocabulary 1 a sensing block which will ask whatever question is typed into the block and display an input text box at the bottom.
CS 1111 Introduction to Programming Spring 2019
getline() function with companion ignore()
Imperative Programming
Python Creating a calculator.
Presentation transcript:

Getting Input in Python Assumes assignment statement, typecasts

Input in Python Most programs need some input from the outside world, i.e. the user The most common input device is the keyboard To get the user’s input into the program, you use the input function built into Python

What to ask about any builtin function? How many arguments does it have? What type are the arguments? What does the function do? (the semantics) What type does the function return? (if it returns anything!)

The input function The input function has one argument, which must be a string. This string is displayed as a “prompt” to the user. The argument can also be empty, that is, nothing between the parentheses. Then nothing is displayed as a prompt. The input function pauses the running of the program, displays the prompt if there is one, shows a blinking cursor, and waits for the user to press the Enter key. When the Enter key is pressed, whatever the user typed at the keyboard is returned as the result of the function. The user can press just the Enter key, in which case the empty string is returned.

Using the input function Since the function returns a value (a string), it must be called as part of a statement Typical calls Answer = input(“What’s your name? “) size = int(input(“How many points? “)) temperature = float(input(“What’s the current temperature? “)) Don’t forget the variable name and assignment operator to the left! Note the typecasts – they are necessary if you are going to use the user’s input as a number