Coders Packet

Python code to obtain the Largest Even Number

By Abirami Somasundaram

To implement a Python program to obtain the largest even number formed from the n spaced digits obtained as input from the user.

To obtain the largest even number formed by creating a number using the n digits obtained as input from user.
Python library "itertools" is used to obtain the possible combinations of the digits, which returns a list containing elements as possible permutations.
A simple 'for' loop traversal will aid in forming a number and obtaining the desired result.

Steps taking place inside the loop:

   1. Form a number using the digits present in i'th combination

   2. Check if the number formed is even and the largest one

Once when the for loop turns out false i.e there are no more elements in the list, display the result stored.

 

 

Below is the snippet of the code for your consideration:

Download Complete Code

Comments

No comments yet