[go: up one dir, main page]

0% found this document useful (0 votes)
4 views6 pages

Input, Output and Import Functions

Uploaded by

ltmonu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Input, Output and Import Functions

Uploaded by

ltmonu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Input, Output and Import

Functions
Python input() Function
 Python input() function is used to take user input. By default, it
returns the user input in form of a string.

 Returns: Return a string value as input by the user.


 By default input() function helps in taking user input as string. If
any user wants to take input as int or float, we just need to
typecast it.
Python input() Function
Example
# Taking input as string
color = input("What color is rose?: ")
print(color)

# Taking input as int


# Typecasting to int
n = int(input("How many roses?: "))
print(n)

# Taking input as float


# Typecasting to float
price = float(input("Price of each rose?: "))
 Example 1: Taking the Name and Age of the user as input and
printing it
Example 2: Taking two integers from
users and adding them.
 In this example, we will be looking at how to take integer input from
users. To take integer input we will be using int() along with Python
input()

# Taking number 1 from user as int


num1 = int(input("Please Enter First Number: "))

# Taking number 2 from user as int


num2 = int(input("Please Enter Second Number: "))

# adding num1 and num2 and storing them in


# variable addition
addition = num1 + num2

# printing
print("The sum of the two given numbers is {} ".format(addition))
 Output:

 Similarly, we can use float() to take two float numbers.

You might also like