Pps Experiment No. 3
Pps Experiment No. 3
Output of program:
Enter a number: 7
7 is an Odd number
Conclusion :
The program checks whether a given number is even or odd by
using the modulus operator (%). If the remainder when divided
by 2 is zero (num % 2 == 0), the number is even; otherwise,
it’s odd. The program takes user input, performs the check, and
then outputs the result.
Experiment no:-03
1. Type Conversion:
Type conversion is the process of converting one data type to
another. This can be done in two ways:
Implicit Type Conversion (Automatic): This is done by
the Python interpreter automatically when you combine
different data types. For example, when you add an
integer and a float, Python automatically converts the
integer to a float to perform the operation.
Explicit Type Conversion (Manual): This is when you
manually convert one data type to another using built-in
functions such as int(), float(), str(), etc.
2. Type Casting:
Type casting is another term used for explicit type conversion.
You are explicitly specifying the type of a variable using the
constructor methods for the required type (like int(), float(),
str())
num1 = 5 # Integer
num2 = 2.5 # Float
result = num1 + num2
print(f"Result of addition (implicit conversion): {result}")
float_num = 5.75
int_num = int(float_num)
print(f"Converted float to integer: {int_num}")
str_num = "100"
int_str = int(str_num) # Converts string to integer
print(f"Converted string to integer: {int_str}")
int_value = 50
str_value = str(int_value)
print(f"Converted integer to string: {str_value}")
int_boolean = int(boolean_value)
print(f"Converted boolean to integer: {int_boolean}") #
Output: 1
integer_value = 12
float_value = float(integer_value)
print(f"Converted integer to float: {float_value}")