mardi 23 janvier 2018

Randomly generating two list, finding odd numbers and comparing the lists

I'm writing a function compare(list_a, list_b) that accepts two lists of integers.

The function does the following:

  1. Counts the number of odd numbers in the first list
  2. Counts the number of odd numbers in the second list
  3. Returns 1, if the first list has more odd numbers
  4. Returns -1, f the second list has more odd numbers,
  5. Returns 0, if both lists have the same amount of odd numbers.

I am writing a main program that testing the function and randomly generate the list of size 15, range of integers from -10 to 10.

Here is what I have so far:

def make_list(size):
        my_list=[]
        for i in range(size):
                my_list.append(int(input("enter integer ")))
        return my_list

def compare(list_a,list_b):
        flist=[]
        slist=[]


        fcount=0


        for i in my_list:
                if(i%2!=0):
                        flist.append(i)
                                fcount+=1

def main():
        size=random.randint(15, -10,10)

main()




Aucun commentaire:

Enregistrer un commentaire