We use the command ‘input ()’ take user-defined inputs into the program. All the inputs from the user are taken as variables of type <class ‘str’ > by default. Hence, if int are taken as input its mandatory to change their class in order to use them as integers for further calculations.
Name= input(‘ What is your name?’)
Output: welcome XXX
#Note that the space between welcome and XXX is produced due to the presence of ‘,’(comma) in the print statement.
Now, let us consider an example program:
Challenging task: European lifts in an apartment is generally marked from zero in the ground floor and later increment 1 on each floor whereas, in the USA, the ground floor is generally marked by 1 and later incremented by 1 to each floor. Write a program to convert an EU floor number to USA floor number.
floor = input(‘Enter EU floor’)
US_floor=int(floor) + 1 #Note: All inputs taken are always stored as strings by default.
print(‘US floor = ‘, US_floor) #Therefore, conversion to int/float for calculations is mandatory.
Enter EU floor 3
US floor =4