Social Media

12/24/2018

Input from user

In python for taking input from the user we  have input() method.
Input method by default treat all inputs as string.
input() function  can take a single string type argument.

x=input()
print(type(x)) #str

Write a script to find out the sum of two numbers:
x=int(input("Enter first number"))
y=int(input("Enter second number"))
sum=x+y
print("The sum is ",sum)

The complex number input format in python is 3+6j etc
Here is  simple script which can take a complex number as input.
x=input()
y=complex(x)
print(type(x),type(y))  #<class 'str'> <class 'complex'>

Be First to Post Comment !
Post a Comment