I have a text file with a single line in it. The line of text is a whole bunch of random numbers. I need to determine the most amount of times a 5 is repeated and print how many times it's repeated. For example: numList: 1234555325146555. The most amount of times 5 is repeated in a row is 3 and that happens 2 times. Here is the code I have so far, it shows me at what positions 5 occurs. I think this is the first step but can't figure out how to move on.
numbers = open("numbers.txt",'rU')
count = -1
numString = numbers.readline()
for num in numString:
count += 1
if num == '5':
print count
counter += 1
You got the right idea for finding out which position the 5 is in.
So how do you find out how long a row of 5's is? Think about:
Good luck! and keep on asking questions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With