1.

. Write a program to input 10 integers and check whether all the entered numbers are even numbers1or not.​

Answer»

Program

A1 = int(input("Enter the first number:\n"))

a2 = int(input("Enter the second number:\n"))

a3 = int(input("Enter the third number:\n"))

a4 = int(input("Enter the fourth number:\n"))

a5 = int(input("Enter the fifth number:\n"))

a6 = int(input("Enter the sixth number:\n"))

a7 = int(input("Enter the seventh number:\n"))

A8 = int(input("Enter the eight number:\n"))

a9 = int(input("Enter the ninth number:\n"))

a10 = int(input("Enter the tenth number:\n"))

l = [a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]

All_the_numbers_are_even = True

for i in range(0,len(l)):

   if(l[i]%2!=0):

       All_the_numbers_are_even = False

       break

if All_the_numbers_are_even:

   print("All the numbers are EVEN.")

else:

   print("All the  numbers are not even.")

Explanation

  • I have used for LOOP to print the result.
  • By default, i have assumed that all the numbers entered by the user are even.
  • Then, i have used break statement. for loop will stop executing as soon as it encounters any odd number and our statement is declared false.

       



Discussion

No Comment Found