#04 - Input and Ouput Operations



In order to interact with the user,s the program needs input and output statements.
For example take a calculator :
we give numbers and operations as input and it gives the result as an output,

In python we have those statements known as:

print() statements:


As the name suggests the print statements prints the output to the screen , and so it is known as a output statement.

SYNTAX:
print(statement)

A syntax can be considered as a formula to write a speific statement. Here, the syntax states that the keyword print() statement refers to the statement or the expression to be printed

EXAMPLE:

  1. print(30)             # output => 30
  2. print(3.32)           # output => 3.32
  3. print('code hub')     # output => code hub
  4. print('code hub', 1)  # output => code hub 1

NOTE: comma(,) is use to seperate two different datatypes that is to be printed in a single print() statement

input() statements:


So, in order to get the input from the user, you need a input statement

SYNTAX:
variable = input(prompt)

so the as the syntax says, anything that we type is observed by the input statement and then it is stored in the varibale prompt. Prompt is nothing but the statment that is printed for the understanding of the user
for example :
consider the following code,
num = input()


in the output you just see the curser blinking but you don't know what you should enter, you may enter your name , age , something link that, to prevent those confusion we can write the following code
print('enter a number : ')
num = input()

so now in the output screen you can see a statement that says to enter a number , so now you know what you should enter BUT, insted of writtin print() and then input() we can write like the following

num = input('enter a number')

so now the output screen shows the same output screen as the before statement but we did the same thing in a single like that single line is known as prompt , so anything within that '' inside the input() will be printed for the user understanding..

EXAMPLE FOR BOTH INPUT AND PRINT STATEMENT:

  1. name = input('enter your name :')
  2. print('hello and welcome to code hub',name)

so the above code give the output as follows:

enter your name : sriram
hello and welcome to code hub sriram