0% found this document useful (0 votes)
21 views

Unit2-Input Output Function

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Unit2-Input Output Function

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Unit-2

Python Input-Output
Function
Input-Output function of Python Program
 Python input function is to accept input from a
user through keyboard
Python has a built-in function input() to accept user input.
Variable=input(“prompt”) # Format/Syntax
Example: Name=input(“Enter your name:”)

Output
Input-Output function of Python Program

The following script is not executed because the input


is not converted from string to integer.
Input-Output function of Python Program

Type conversion/Data Type:


 Whatever you enter as input, the input() function converts it into a string.
 If you enter an integer value, still it will convert it into a string.
 If you want a number input from a user, you need to perform type conversion on the
input value.
 We need to convert an input string value into an integer using a int() function. (round
number)
 We need to convert an input string value into float using a float() function. (with point)
Input-Output function of Python Program

Calculate the area of floor/rectangle


Built-in Data Types:

In programming, data type is an important concept.

Variables can store data of different types, and different types can do
different things.

Python has the following data types built-in by default, in these


categories:

Text Type: str


Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Setting The Specific Data types
Example Data Type
x = "Hello World" str
x = 20 int
x = 20.5 float
x = 1j complex
x = ["apple", "banana", "cherry"] list
x = ("apple", "banana", "cherry") tuple
x = range(6) range
x = {"name" : "John", "age" : 36} dict
Getting Data Types:

You can get the data type of any object by using the type() function:

Example:

Print the data type of the variable x, y and z:


Output
x=5
print(type(x)) <class
'int'>
y= 5.5
print (type(y)) <class
'float'>
z=1j
<class 'complex'>
print(type(z))
Practice the following examples using
input function:
Height=int(input(“Enter the height:”))
 Write a python script to Width=int(input(“Enter your width:”))
print the volume of a Length=int(input(“Enter the Length:”))
vol= length*width*height
room. print (“Volume =“, vol, “sqr root”)

 Write a python script toradius=int(input(“Enter the radius:”))


area_circle= 3.14*radius*radius
print the area of a print ("Area Circle=", area_circle,"sqr_root")
circle.
 Write a python script to
print the area of a
triangle.
Python Operators:
Operators are used to perform operations on variables and
values.
Python divides the operators in the following groups:

 Arithmetic operators
 Assignment operators
 Comparison operators
 Logical operators

You might also like