Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

part2.py Read in a list of numbers entered by the user. The user will enter inte

ID: 642490 • Letter: P

Question

part2.py Read in a list of numbers entered by the user. The user will enter integers, and when they are done they will type "end". You should print out the length of the longest subsequence of repeated elements. That is, the largest number of times something is repeated. So for the list [1, 4, 4, 3], you should print out "2", because there are two fours in a row. For the list [1, 2, 3, 3, 4, 1, 1, 1] you should print out "3", because there are three 1s in a row. Please format your results as follows:

Explanation / Answer

Here maxVal is the value for which max run is increased, count is the run for current num, while maxCount is the longest run till now.

maxVal = 0
maxCount = 0
count = 0
while 1:
   var = raw_input("Enter a number:")
   if(str(var)=='end'):
       print "Longest run was %d long" % (maxCount)
       break
   elif maxVal == int(var):
       count += 1
   else:
       maxVal = int(var)
   count = 1
   if count > maxCount:
       maxCount = count