short hand if else in Python

Given fig. show how input() statement works in python.
User feed the input to python program or script using input() function.
input() Function: the input() function in python prompt the user and accepts the input in the form of string.
input() pause the python progra till user does not provide any input from the keyboard.
Once the input is given the code or program process it, after processing the print() display or send the processed data on console i.e. output device(console).


Example 1: Python script to accept different types of values in a Program.


1. Taking input using input() , The default method in Python takes input as string.
name=input("Enter Your Name")
input() prompt the user with the message
"Enter Your Name"
Guido van Rossum
the name entered is Guido van Rossum which is get stored in name variable.


2. Accepting integer input using input()
age=int(input ("Enter Your age"))
The above function prompts "Enter Your age" .
let say we have entered 19 . 19 is considered string by input() so that we have type cast it in to the int data type.


3. Accepting Float value in python using input()
Python do not have any method to get input as float value.
we know that python read input as string but string can be converted to float using float() function.

# python script to input float value.
height=float(input(" Enter Your Height"))


4. Accepting Complex Value in Python using input()
cmplx=complex(input("Enter Complex Number"))
print("The Complex Number is ",cmplx)
output:
Enter complex Number
11+3j
The Complex Number is 11+3j


5. Accepting boolean value in Python using input()
b=bool(input("Enter value to be convert in boolean"))
print("The Value Entered in Boolean is :->",b)
output:
Enter value to be convert in boolean
1
The Value Entered in Boolean is :->True


6. Accepting tuple in Python using input()
t=input("Enter the tuple :")
t=tuple(int(a) for a in t.split(","))
print("The Tuple is-->",t)
output:
Enter the tuple :
1,2,45,67,89,23,12,50
The Tuple is--> (1,2,45,67,89,23,12,50)



Previous Topic:-->> Special Operator in Python || Next topic:-->>Output in Python