In the previous tutorials, we directly assign the values into variables before we run the program. How about if you want to enter your own values while the program is up and running. In Python this what we call as user input. Example
name = input("Your name: ")
age = input("Your age: ")
print("Your name is Mr/Mrs" + name)
print("And you are " +age+ " years old")
When you using function input(), it returns string as default, so you need to cast it using type conversion that we're already talk about in Python operators, when you're writing arithmetic program. Example
a = int(input("Enter a: "))
b = int(input("Enter b: "))
print('a + b = {}' .format(a + b))
print('a - b = {}' .format(a - b))
print('a * b = {}' .format(a * b))
print('a / b = {}' .format(a / b))
0 Response to "5. Python User Input"
Post a Comment