December 05, 2017

Python Input Function

Python is really cool and fun to play around. Lets write a simple program to ask user enter their name and age. To do this here, we're going to use python input function

CODE

name = input("What is your name?: ")
print(name)

age = input ( "How old are you?: " )
print(age)


OUTPUT

name = input("What is your name?: ")
What is your name?: Xayah
print(name)
Xayah

age = input ( "How old are you?: " )
How old are you?:19
print(age)
19


Now, lets make it more interesting by telling python to display the name and the age of the user in one line.

 CODE

name = input("What is your name?: ")
print(name)

age = input("Enter your age: ")
print(name, "is", age, "years old.")


OUPUT

name = input("What is your name?: ")
What is your name?: Xayah
print(name)
Xayah

age = input("How old are you?: ")
How old are you?:19
19
print(name, "is", age, "years old.")
Xayah is 19 years old. 


No comments :

Post a Comment