Input method

Python program uses input method to take input from user and based upon that input it gives output or sometime use that input in further program. eg , the website , “Enter your name : “. so,it taking and storing the name in profile of user. also,sometime it check whether the given email address is present or not. if present it gives email addresd already exist.

Syntax : input(prompt)

name = input(“Enter your name: “)

Output: Enter your name : ■■■

The input method is in string method. In place of ■■■ we store our name :vipul,jack etc. then it give output vipul or jack .

***It also taking the integer or float , form of string.***

age = input(“Enter your age : “)

Output: Enter your age : 19

Here,we had put age 19. we have to check what is the data type of 19.

>>>age

’19’

So,we had seen 19 is in string .

Basically,19 is integer so we have to convert string 19 in integer 19.

age = int(age)

In this time,

>>> age

19

Example,To check person is applicable to voting or not.

age = input(“Enter your age: “)

# convert string number to integer

age = int(age)

# check that person is applicable for voting or not.

if age >18:

print(“you are applicable to voting !”)

else:

print(“you are not applicable to voting !”)

Output:

Enter your age: 19

you are applicable to voting !

🙂🙂✒✒

Leave a comment