Page 119 - Computer Genius Class 08
P. 119
Creator Guido van Rossum named the language 'Python', after the popular
BBC comedy series "Monty Python's Flying Circus”. He wanted to select a
name that was a little bit mysterious and unpredictable.
Input Statement in Python
In python, to take input from the user we use input() function. This input() function prompts the
user to enter data.
Syntax:
input([ prompt] )
This input() considers all user input as string. Whether the user enters a number or a string but the
input() treats them as strings only. So, in order to consider the input value as other than string, we
have to convert it into other datatype.
For example:
A=input("Enter your N ame") Here the input entered is String
#
B=input("Enter your mark s") # Here the input is again String, but we cannot do
calculations on String. So it is converted into other data types.
Thus, the changed statement will be:
B=int(input("Enter your Mark s") ) To enter integer data values.
#
C=float(input("Enter your Price of the item")) # To input decimal values.
Output Statement in Python
The print() outputs a complete line and then moves to the next line for subsequent output.
Syntax:
print(value[ ,… .sep= " ",end='\n'] )
For example:
a=10
print("value of a",a)
Example 1: Input and Output statements in Python
Program: Output:
# Python program to swap two variable
enter first number 3
values
enter second number 45
num1=int(input("enter first number"))
Now the value of num1 45
num2=int(input("enter second number"))
Now the value of num2 23
temp=num1
num1=num2
num2=temp
print("N ow the value of num1",num1)
print("N ow the value of num2",num2)
Basics of Python 117

