1.3 Input/Output

Basic output
The print() function displays output to the user. Output is the information or result produced by a program.
The sep and end options can be used to customize the output.

Table 1.1 shows examples of sep and end.
Multiple values, separated by commas, can be printed in the same statement. By default, each value is separated by a space character in the output. The sep option can be used to change this behavior.
By default, the print() function adds a newline character at the end of the output. A newline character tells the display to move to the next line. The end option can be used to continue printing on the same line.

print(“Today is Monday.”)
print(“I like string beans.”)
Today is Monday.
I like string beans.
print(“Today”, “is”, “Monday”)
print(“Today”, “is”, “Monday”, sep=”‚Ķ”)
Today is Monday
print(“Today is Monday, “, end=””)
print(“I like string beans.”)
Today is Monday, I like string
print(“Today”, “is”, “Monday”, sep=”? “,
print(“I like string beans.”)
Today? is? Monday!!I like string

Basic input
Computer programs often receive input from the user. Input is what a user enters into a program. An input
statement, variable = input(“prompt”), has three parts:

  1. A variable refers to a value stored in memory. In the statement above, variable can be replaced with any
    name the programmer chooses.
  2. The input() function reads one line of input from the user. A function is a named, reusable block of code
    that performs a task when called. The input is stored in the computer’s memory and can be accessed later
    using the variable.
  3. A prompt is a short message that indicates the program is waiting for input. In the statement above,
    “prompt” can be omitted or replaced with any message.

Leave a Reply