How to Allow a User to Input Range in Python

Python is a free, interpretive, programming language based on object-oriented principles. When programming in Python, you may need to capture data in a range based on input from your users. For example, you may wish to ask students to input three of their most recent grades using one prompt and one input field. You can capture a range of data using Python's built-in raw_input function.

Instructions

    • 1

      Access your Python editor.

    • 2

      Create a variable to prompt the user for the range and store the input. For example, type:

      scoreRange = raw_input ("Please input your grades in this order - first, best, worst : ")

    • 3

      Press "Enter." Continuing the example, Python prompts the user:

      Please input your grades in this order - first, best, worst :

      The user enters his grades. For example, the user enters:

      86, 99, 85

      Python stores the three values as a string and returns:

      '86, 99, 85'

Tips & Warnings

  • Python stores the values as a string. If you would like the values in a different format, such as an integer or float, use the appropriate function to split and convert the data.

  • Do not use the input function to capture user-entered data. Input permits the user to enter any type of data, such as commands to manipulate your database. For security reasons, use the raw_input function to limit users to entering only strings.

Related Searches:

References

Comments

Related Ads

Featured