Python - Input and Output
Python - Input and Output
Table of Contents
2. Hard coding
age = 16
print(age)
output
16
3. input(p) function
Run py demo2.py
Output
Enter the name: Daniel
You entered name as: Daniel
Run py demo3.py
Output
Enter the name: Prasad
Enter the age: 16
Run py demo4.py
Output
Enter the value: Daniel
Entered value as: Daniel
type is: <class ‘str’>
Run py demo4.py
Output
Enter the value:123
Entered value as: 123
type is: <class 'str'>
Run py demo4.py
Output
Enter the value:123.456
Entered value as: 123.456
type is: <class 'str'>
a = "123"
print(a)
print(type(a))
b = int(a)
print(b)
print(type(b))
Output
123
<class 'str'>
123
<class 'int'>
a = input("Enter a value:")
print("Your value is:", a)
print("data type is:", type(a))
b = int(a)
print("After converting the value is:", b)
print("data type is:", type(b))
Run py demo5.py
Output
Enter a value:123
Your value is: 123
data type is: <class 'str'>
After converting the value is: 123
data type is: <class 'int'>
a = "123.99"
print(a)
print(type(a))
b = float(a)
print(b)
print(type(b))
Output
123.99
<class 'str'>
123.99
<class 'float'>
a = input("Enter a value:")
print("Your value is:", a)
print("data type is:", type(a))
b = float(a)
print("After converting the value is:", b)
print("data type is:", type(b))
Run py demo9.py
Output
Enter a value:123.99
Your value is: 123.99
data type is: <class 'str'>
After converting the value is: 123.99
data type is: <class 'float'>
a = 10000.45
print(a)
print(type(a))
b = int(a)
print(b)
print(type(b))
Output
10000.45
<class 'float'>
10000
<class 'int'>
Run py demo11.py
Output
a = int(p1)
b = int(p2)
Run py demo12.py
Output