Sometimes, you want the user to give a value to run the program, for example, you want the user to give you his name so you can display it. So, you write
Name=input("Give me your name")
print(Name)
When you run this program, you will see the note "Give me your name" when you input a name it will be printed to screen.
Sometimes you want a specific type of input from user, for example you want an integer if you ask him/her for age or you want string in case of name and if you want to know the age you should use a decimal or floating point value called float. To ask for certain types of values use following functions.
str() for string input
int() for integer
float() fot decimal value
Now look at the program below
age=int(input("Your age: "))
name = str(input("Your name: "))
weight=float(input("You weight: "))
Read the program carefully and run it try to input differen values for each type,like input a string in the int part or put a number in the string or float
Note: String can take any value including float or int since normal sentence contains both alphabets and numbers.While float can take any integer or floating point value eg 12 or 12.0 and integer can take only whole int value.
YOU ARE READING
Python Guide for Beginners
RandomThis is an easy to learn and absolutly no programming experience is required.You can start learning by opening this book right now.
