I am trying to generate two arrays, a and b, each containing ~1000 random numbers. The random number are between 1 and 5.
I want to then compare each element in a with the corresponding element of b such that if a[i] > b[i] a variable, counter, will be incremented by 1. This is considered a "success". Otherwise, if a[i] <= b[i] nothing happens (i.e counter += 0). This is considered a "fail".
However, a and b can be of variable length such that both len(a) == len(b) and len(a) != len(b) are possibilities.
In the case of the latter, if len(a) > len(b) I'd like all the "extra" elements of a to automatically be counted as "successes". If len(b) > len(a) things should proceed normally (i.e the "extra" elements of b are ignored).
For example:
If a = [1, 3, 4, 2] and b = [2, 4, 0]
Then counter = 2 because (1 < 2, 3 < 4, 4 > 0, and 2 is extra and is an automatic success`)
How would I go about doing this?
Here is some quick code, which returns the expected list index out of range... error:
import random
a = []
b = []
counter = 0
for i in range(1000):
a += [random.randint(1, 5)]
for i in range(900):
b += [random.randint(1, 5)]
for i in range(len(a)):
if a[i] > b[i]:
counter += 1
print counter