Page 449 - CITS - Computer Software Application -TT
P. 449
COMPUTER SOFTWARE APPLICATION - CITS
# Taking input from the user
name = input(“Enter your name: “)
# Output
print(“Hello, “ + name)
print(type(name))
Output:
Enter your name: NSTI
Hello, NSTI
<class ‘str’>
Note: Python takes all the input as a string input by default. To convert it to any other data type we have to convert
the input explicitly. For example, to convert the input to int or float we have to use the int() and float() method
respectively.
Example 2: Integer input in Python
• Python3
# Taking input from the user as integer
num = int(input(“Enter a number: “))
add = num + 1
# Output
print(add)
Output:
Enter a number: 25
26
How to take Multiple Inputs in Python :
we can take multiple inputs of the same data type at a time in python, using map() method in python.
• Python3
a, b, c = map(int, input(“Enter the Numbers : “).split())
print(“The Numbers are : “,end = “ “)
print(a, b, c)
Output :
Enter the Numbers : 2 3 4
The Numbers are : 2 3 4
Python output
How to Display Output in Python
Python provides the print() function to display output to the standard output devices.
Syntax: print(value(s), sep= ‘ ‘, end = ‘\n’, file=file, flush=flush)
Parameters:
value(s) : Any value, and as many as you like. Will be converted to string before printed
sep=’separator’ : (Optional) Specify how to separate the objects, if there is more than one.Default :’ ‘
end=’end’: (Optional) Specify what to print at the end.Default : ‘\n’
file : (Optional) An object with a write method. Default :sys.stdout
436
CITS : IT&ITES - Computer Software Application - Lesson 120 - 137