Python - How to get user input

By xngo on June 7, 2019

#!/usr/bin/python3
# Description: How to get user input.
 
name = input("Enter your name : ") 
age = input("Enter your age : ") 
salary = input("Enter your salary : ")
 
# Convert inputs to the appropriate data type because
#   input() returns value entered as string.
age = int(age)
salary = float(salary)
 
print("My name is {}({}).".format(name, type(name)))
print("My age is {}({}).".format(age, type(age)))
print("My salary is {}({}).".format(salary, type(salary)))

Output

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.