Password Protection

Password Protection

The owner of a block layout has some plot numbers with odd numbers and some with even numbers. He is maintaining the details in a file in the system. For the password protection the owner has followed one formula. He calculated the sum of his even number plots and sum of odd number plots and found the average of those two and he used that average as his password for the file.   Write a Python program to arrive at the password for the file, by entering the plot numbers. 

Input and Output Format:
Input consists of n+ 1 numbers. The first number corresponds to n which is the number of plots. The next ‘n’ numbers correspond to the plot numbers and these plot numbers can be integers or floats.

Output consists of a floating point number that corresponds to the average. It is display with  2 decimal places.  Assume that the maximum number of plots should not be greater than 20.


  1. The size of the list should always be a positive number between 1 and 20. If not, display the message “Invalid Input” and terminate the program.
  2. While entering list elements, make sure that you enter positive values only.   If not, it should print “Invalid Input” and terminate the program immediately.
  3. Use list comprehension for finding odd and even numbers.

Sample Input 1:
Enter the total no.of plots: 5
Enter the numbers of each plot:
Sample Output 1:
The password for the file is: 7.50
Sample Input 2:
Enter the total no.of plots: -5
Sample Output 2:
Invalid Input
Sample Input 3:

Enter the total no.of plots: 5
Enter the numbers of each plot:
Sample Output 3:
Invalid Input
Sample Input 4:

Enter the total no.of plots: 8
Enter the numbers of each plot:
Sample Output 4:
Invalid Input
Sample Input 5:
Enter the total no.of plots: 21
Sample Output 5:
Invalid Input

Code :-

n1=int(input("Enter the total no.of plots: "))
if n1<=20 and n1>=1:
    print("Enter the numbers of each plot")
    for i in range(n1):
        if i<=0:
            print("Invalid Input")
        o=(sum([i for i in l if i%2!=0]))
        e=sum([i for i in l if i%2==0])
    print("The password for the file is: %.2f" % avg)
    print("Invalid Input")

1 thought on “Password Protection”

  1. I’m not sure exactly why but this web site is loading incredibly slow for me.
    Is anyone else having this problem or is it a problem
    on my end? I’ll check back later on and see if the problem still

Leave a Comment

Your email address will not be published. Required fields are marked *