0% found this document useful (0 votes)
6 views3 pages

Pps Experiment No. 3

The document describes a program that determines if a number is even or odd using the modulus operator. It also explains type conversion in Python, detailing implicit and explicit conversions, along with examples of converting between different data types. The conclusion emphasizes the functionality of the program and the importance of type conversion in programming.

Uploaded by

snehuuuu2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Pps Experiment No. 3

The document describes a program that determines if a number is even or odd using the modulus operator. It also explains type conversion in Python, detailing implicit and explicit conversions, along with examples of converting between different data types. The conclusion emphasizes the functionality of the program and the importance of type conversion in programming.

Uploaded by

snehuuuu2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment no:-03

Title : Program to find whether the given number is even


or odd

num = int(input("Enter a number: "))


if num % 2 == 0:
print(f"{num} is an Even number.")
else:
print(f"{num} is an Odd number.")

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}")

You might also like