Table of Contents

    What is Input?

    Programming Mastery

    Input and Output

    Learn how programs receive data, process it, and communicate results back to users. This lesson focuses on the first concept: what input means in programming.

    1. What is Input?

    Input means data or information that is given to a program so that the program can use it, process it, and produce a result.

    In simple words, input is the information that goes into a program. A program may receive input from a user, keyboard, mouse, file, form, database, sensor, microphone, camera, or another system.

    Input is the data that a program receives before it performs processing.

    For example, when a calculator asks you to enter two numbers, those numbers are input. When a login form asks for username and password, those values are input. When a student result program asks for marks, the marks are input.

    Easy Real-Life Example

    Input as Calculator Data

    Imagine you are using a calculator. You press 5, then +, then 3. The numbers and operator you enter are input.

    The calculator takes your input, processes it, and then shows the answer 8 as output.

    Input in Programming

    In programming, input allows a program to become interactive. Without input, a program can only work with fixed values written inside the code. With input, a program can accept different values from the user and produce different results.

    Example Without Input

    SET numberOne = 10
    SET numberTwo = 20
    
    SET sum = numberOne + numberTwo
    
    DISPLAY sum

    In this example, the numbers are fixed. The user cannot change them while the program is running.

    Example With Input

    INPUT numberOne
    INPUT numberTwo
    
    SET sum = numberOne + numberTwo
    
    DISPLAY sum

    In this example, the program accepts values from the user. Because of input, the program can work with different numbers each time it runs.

    Why is Input Needed?

    Input is needed because most programs must work with data provided by users or external sources. A program becomes useful when it can receive information, process it, and return meaningful output.

    Main Reasons for Input

    • To allow users to enter data.
    • To make programs interactive.
    • To process different values each time the program runs.
    • To collect information from forms, files, or devices.
    • To perform calculations using user-provided values.
    • To make decisions based on user choices.
    • To customize program behavior.
    • To connect programs with the outside world.

    Input, Process, Output Flow

    Input is the first part of the common Input → Process → Output model.

    Stage Meaning Example
    Input Data received by the program. User enters marks.
    Process Program performs calculation or logic. Program calculates average marks.
    Output Program displays or returns result. Program shows pass or fail.

    Simple IPO Example

    INPUT marks
    
    IF marks >= 35 THEN
        DISPLAY "Pass"
    ELSE
        DISPLAY "Fail"
    END IF

    Here, marks is the input. The condition checks whether marks are greater than or equal to 35. The result displayed is the output.

    Common Sources of Input

    A program can receive input from many sources.

    Input Source Description Example
    Keyboard User types data. Name, age, marks, password.
    Mouse / Touch User selects or clicks something. Button click, menu selection.
    Form User fills data fields. Registration form, login form.
    File Program reads stored data. CSV file, text file, configuration file.
    Database Program reads stored records. Student details, product records.
    Sensor Device sends measured data. Temperature, speed, heart rate.
    Network / API Program receives data from another system. Weather data, payment response.

    User Input

    User input is data entered by a person while the program is running.

    User input is common in beginner programs because it helps students understand how a program interacts with users.

    Example: Asking for Name

    INPUT studentName
    
    DISPLAY "Welcome"
    DISPLAY studentName

    Here, the program asks the user to provide a name. That name is stored in the variable studentName.

    Examples of Input Values

    Program Type Possible Input Purpose
    Calculator 10, 20, + To calculate a result.
    Login System Username and password To verify user identity.
    Student Result Program Marks of subjects To calculate total, average, and result.
    Billing System Price and quantity To calculate total bill amount.
    Search System Search keyword To find matching results.

    Input and Variables

    Input values are usually stored in variables so that the program can use them later.

    INPUT age
    
    DISPLAY age

    In this example, the value entered by the user is stored in the variable age.

    Important: A program should store input in meaningful variables so that the code is easy to understand.

    Good Variable Names for Input

    Input Data Good Variable Name
    Student name studentName
    Student age studentAge
    Product price productPrice
    Quantity quantity
    Marks marks

    Input is Often Text First

    In many programming languages, input entered by the user is first received as text. If the program needs to perform calculations, the input may need to be converted into a number.

    Example: Text Input Converted to Number

    INPUT ageText
    
    SET age = CONVERT ageText TO INTEGER
    
    SET nextAge = age + 1
    
    DISPLAY nextAge

    Here, the user input is first treated as text. It is converted to an integer before doing arithmetic.

    Beginner Rule: If input is needed for calculation, make sure it is converted into the correct numeric type before using arithmetic operators.

    Input Validation

    Input validation means checking whether the input is correct, acceptable, and safe before using it.

    Programs should not blindly trust input. Users may enter wrong, empty, invalid, or unexpected data. Validation helps prevent errors.

    Example: Checking Age Input

    INPUT age
    
    IF age >= 0 THEN
        DISPLAY "Valid age"
    ELSE
        DISPLAY "Invalid age"
    END IF

    This program checks whether the age is valid before accepting it.

    Common Input Problems

    Input Problems

    • User enters text when a number is expected.
    • User leaves the input empty.
    • User enters negative value where only positive value is valid.
    • User enters very large or very small values.
    • User enters wrong format.
    • Program does not convert input before calculation.
    • Program does not validate input.

    Better Habits

    • Ask clear questions to the user.
    • Use meaningful input prompts.
    • Store input in meaningful variables.
    • Convert input to the required data type.
    • Validate input before processing.
    • Show helpful error messages.
    • Test input with different values.

    Complete Example: Student Marks Input

    The following language-neutral example shows how input is used in a student marks program.

    /*
    This program accepts student marks as input
    and displays whether the student passed or failed.
    */
    
    CONSTANT PASS_MARK = 35
    
    ENTRY POINT
        DECLARE studentName AS TEXT = ""
        DECLARE marks AS INTEGER = 0
    
        INPUT studentName
        INPUT marks
    
        IF marks >= PASS_MARK THEN
            DISPLAY studentName
            DISPLAY "Pass"
        ELSE
            DISPLAY studentName
            DISPLAY "Fail"
        END IF
    END ENTRY POINT

    In this program, studentName and marks are input values. The program processes the marks and displays the result.

    Real-World Example: Billing System Input

    ENTRY POINT
        DECLARE productName AS TEXT = ""
        DECLARE productPrice AS DECIMAL = 0.0
        DECLARE quantity AS INTEGER = 0
        DECLARE totalAmount AS DECIMAL = 0.0
    
        INPUT productName
        INPUT productPrice
        INPUT quantity
    
        SET totalAmount = productPrice * quantity
    
        DISPLAY productName
        DISPLAY totalAmount
    END ENTRY POINT

    Here, product name, price, and quantity are input. The program uses them to calculate the total bill.

    How Input Helps Debugging

    Understanding input helps students debug programs because many errors happen due to wrong or unexpected input values.

    Debugging Questions

    • What input value did the user enter?
    • Was the input stored in the correct variable?
    • Is the input text, number, or boolean?
    • Does the input need type conversion?
    • Is the input value valid?
    • What happens if the user enters empty input?
    • What happens if the user enters invalid data?
    • Is the program giving clear instructions before input?

    Best Practices for Input

    Good input handling makes programs easier to use and less likely to fail.

    Recommended Practices

    • Use clear prompts when asking for input.
    • Store input in meaningful variable names.
    • Convert input to the correct data type before calculation.
    • Validate input before processing it.
    • Do not assume the user will always enter correct data.
    • Handle empty or invalid input carefully.
    • Use constants for fixed rules such as pass marks or limits.
    • Test programs with different input values.
    • Keep input, processing, and output logically separated.
    • Write user-friendly error messages.

    Prerequisites Before Learning Input

    To understand input properly, students should already know a few basic programming concepts.

    Basic Prerequisites

    • What is a program?
    • Input, process, output model.
    • Variables and constants.
    • Data types.
    • Type conversion and type casting.
    • Operators and expressions.
    • Basic conditional statements.

    Practice Activity: Identify Input

    Read the following scenarios and identify the input values.

    Scenario Input Values
    A calculator adds two numbers. ________________________
    A login system checks username and password. ________________________
    A billing program calculates total price. ________________________
    A student result program calculates average marks. ________________________
    A search engine searches for a keyword. ________________________

    Sample Answers

    Scenario Input Values
    A calculator adds two numbers. First number and second number.
    A login system checks username and password. Username and password.
    A billing program calculates total price. Product price and quantity.
    A student result program calculates average marks. Marks of different subjects.
    A search engine searches for a keyword. Search keyword.

    Mini Quiz

    1

    What is input?

    Input is data or information given to a program so that the program can process it.

    2

    Give one example of input.

    A user entering their name in a form is an example of input.

    3

    Why is input important?

    Input is important because it allows programs to receive data and work with different values.

    4

    Where is input usually stored?

    Input is usually stored in variables.

    5

    Why should input be validated?

    Input should be validated to make sure it is correct, safe, and suitable for processing.

    Interview Questions on Input

    1

    Define input in programming.

    Input in programming is the data received by a program from a user, file, device, database, or another source.

    2

    How does input make a program interactive?

    Input allows users to provide values while the program is running, so the program can respond based on those values.

    3

    What is the relationship between input and variables?

    Input values are commonly stored in variables so the program can use them later during processing.

    4

    Why might input need type conversion?

    Input may need type conversion because some input is received as text, but calculations require numeric values.

    5

    What are common sources of input?

    Common input sources include keyboard, mouse, forms, files, databases, sensors, and network systems.

    Quick Summary

    Concept Meaning
    Input Data received by a program.
    User Input Data entered by a user while the program runs.
    Input Source Place or device from which input comes.
    Input Variable Variable used to store input data.
    Input Validation Checking whether input is correct and acceptable.
    Input in IPO Model The first stage before processing and output.

    Final Takeaway

    Input is the data that goes into a program. It allows programs to interact with users, receive values, process information, and produce useful results. In the Programming Mastery Course, students should understand input as the starting point of most programs. A good programmer collects input clearly, stores it in meaningful variables, converts it when needed, and validates it before processing.