PYTHON tutorial part-3(Tamil)


PYTHON tutorial part-3




Taking an input in PYTHON

In python, input() function has used to get input from a user. This is a simple function, but the only drawback is that it can only give one input at a time.

Syntax


variable=input("Prompt String")

Parameters:

Prompt string
It is a string to represent what the user has to type.

#Example code to take input

str=input("Enter your Name:")
print("Hi",str,"!")

Output:


Enter your Name: Velan
Hi Velan!

The input() function only gave strings. But How to take a number as an input?. Don't worry, have a look at the below code.


#taking a number as input
num1=int(input("Enter number1:"))
num2=int(input("Enter number2:"))
print("sum of",num1,num1,":",num1+num2)

Output:


Enter number1:78
Enter number2:22
sum of 78 22 :100

Is it looks so easy to you? okay. The int() function has used to take input as a number. The int() convert a given string to input. Many more types of data like this can be obtained using different types of functions. First, we will look at some basic data types.

No.  Data     types    Functions          value(s)
1 string str() A group of character.Example:"Hello World!"
2 integer int() A integer value. Example:79,-5
3 float float() A decimal integer.Example:29.98,-90.6
4 complex complex() A complex number. It has two parts 'real' and 'imaginary'.Example:10+3j,6-6j.Here '10' is the real part and '3j' is imaginary.
5 Boolean bool() It has two values, 'True' and 'False'. Example: True. 0 and 1 are also meant False and True.

Let’s look at several more examples.


#using str()
word=str(10.0)

#using int()
intnum=int(input("Type any integer:"))

#using float()
floatnum=float(input("Type any float number:"))

#using complex()
complexnum=complex(input("Type any complex number:"))

#using bool()
boolnum=bool(int(input("Type any boolean value:")))

print("Word :",word)
print("integer :",intnum)
print("float :",floatnum)
print("complex :",complexnum)
print("boolnum :",boolnum)

Output:

Type any integer: 88
Type any float number: 3.1415
Type any complex number: 5+9.5j
Type any boolean value: 0
Word : 10.0
integer : 88
float : 3.1415
complex : (5+9.5j)
boolnum : False

Try Here what you learned

Comments