User input in python?

 User input in Python

1.input() is a predefined function which is used to take user input in Python.
2.Default user input is of type string.


name=input("Enter your name:")
print("Your name:",name)
#Printing of data type of name
print(type(name))
"""
***Output***
Enter your name:Aayushi
Your name: Aayushi
<class 'str'="">
"""
</class>

1.int() is a predefined function which is used to convert string into integer.


#method 1
number=input("Enter any number:")
print("Type of number:",type(number))
#converting string into integer
num=int(number)
print("Given Number:",num)
#Printing of data type of num
print("Type of number:",type(num))
"""
***Output***
Enter any number:204
Type of number: <class 'str'="">
Given Number: 204
Type of number: <class 'int'="">
"""
</class></class>

#method 2
number=int(input("Enter any number:"))
print("Given Number:",number)
#Printing of data type of number
print("Type of number:",type(number))
"""
***Output***
Enter any number:204
Given Number: 204
Type of number: <class 'int'="">
"""
</class>

1.float() is a predefined function which is used to convert string into float.


marks=float(input("Enter your marks:"))
print("Your Marks is:",marks)
#Printing of data type of marks
print("Type of number:",type(marks))
"""
***Output***
Enter your marks:84.2
Your Marks is: 84.2
Type of number: <class 'float'="">
"""
</class>

Comments

Popular posts from this blog

Coding standards?

programming language?

Computer programming languages?