Friday, 10 September 2021

AGE GENERATOR IN PYTHON


GLSW4E BOOKS FACEBOOK  W4E INSTAGRAM W4E YOUTUBEW4E HOME
FOLLOW US


THIS PROGRAM TAKE PEOPLES AGES AS INPUT AND PRINT OUT THE SUM OF THE EVEN AGES

print(colored('###################################################', 'red'))

print("program that sums value of age")

x = int(input("enter the total persons: \n"))

print("we want to find the average of  ",  x, "  workers\n")

def getage():

        a = 0

         k = 0

         k2 = 0

         while a < x:

               a = a + 1

               name = input("What's your name? ")

                 age = int(input("Your age? "))

                 print(colored("Nice to meet you " + name + "!", 'blue'))

                 if age % 2 == 0:

                 print("your age is even:\n")

                 k = k + age

                  elif age % 2 != 0:

                            print("your age is odd:\n")

                            k2 = k2 + age

                      else:

                            print("please enter only numbers\n")

                              print(colored("The sum of the even ages = {}".format(k), 'green'))

                              print("and the average = ", k/x, "\n")

                               print(colored("But the sum of the odd ages = {}".format( k2), 'green'))

                               print("and the average = ", k2/x, "\n")

getage()

print("Thanks and goodbye")

No comments:

Post a Comment