My problem:
Write a program that generates 100 random integers that are either 0 or 1.
Then find the:
- longest run of zeros, the largest number of zeros in a row. For instance, the longest run of zeros in
[1,0,1,1,0,0,0,0,1,0,0]is4.
I've already generated 100 random numbers between 0 and 1. However, I am not sure about my second function. I iterated my list and if any element was zero I returned the value. I also put the continue statement in order to break the loop if any value was diferent from zero.
import random
l=[]
def list():
for j in range(0,100):
x=random.randint(0,1)
l.append(x)
return list
print(list())
def largest_row_of_zeros(l):
c=0
for j in l:
while j==0:
c+=1
continue
return c
print(largest_row_of_zeros(l))
My compiler does not return any value at all.
This is what appears:
input
<function list at 0x7f6a170dcbf8>
^CTraceback (most recent call last):
File "main.py", line 26, in <module>
print(largest_row_of_zeros(l))
File "main.py", line 24, in largest_row_of_zeros
continue
KeyboardInterrupt
whileto anifin the second function and then try it out.1and start couning new zeros. But you have to remeber previouscto compare with newcand get bigger value.