5. Python User Input

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))

Subscribe to receive free email updates:

Related Posts :

  • 9. Python Lists List is one of python data types which defined with comma-separated values (items) between square brackets. Important thing about a list… Read More...
  • 4. Python Operators In this tutorial you will learn operators that supported by Python. The following are Python operators. 4.1 Arithmetic Operator Arit… Read More...
  • 5. Python User Input 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… Read More...
  • 7. Python Loops In Programming, there might be situation that you need to execute particular block of code multiple times. Python loop provides various s… Read More...
  • 8. Python Strings String is one of Python data types that we've talked about in our previous tutorial, now we're going to learn more about Python string a… Read More...

0 Response to "5. Python User Input"

Post a Comment