Getting input in python
This presentation is the property of its rightful owner.
Sponsored Links
1 / 5

Getting Input in Python PowerPoint PPT Presentation


  • 86 Views
  • Uploaded on
  • Presentation posted in: General

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.

Download Presentation

Getting Input in Python

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Getting input in python

Getting Input in Python

Assumes assignment statement, typecasts


Input in python

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

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

  • 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

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


  • Login