This is a question form my programming lab:
Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value is considered a CONSECUTIVE DUPLICATE. In this example, there are three such consecutive duplicates: the 2nd and 3rd 5s and the second 6. Note that the last 3 is not a consecutive duplicate because it was preceded by a 7. Write some code that uses a loop to read such a sequence of non-negative integers, terminated by a negative number. When the code finishes executing, the number of consecutive duplicates encountered is printed. In this case,3 would be printed. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.
Here is my code:
firstNumber=-1
secondnumber=-1
count=0
firstNumber=input(int())
while int(firstNumber) > 0:
secondnumber=input(int())
if secondnumber == firstNumber:
count+=1
else:
firstNumber=secondnumber
print(int(count))
when I run the code in the MPL if for example the input is:
stdin.txt:·"1↵ 1↵ 1↵ 1↵ 1↵ 1↵ -1
the result is like this:
Expected Output: _stdout.txt:·"5↵ Actual Output: _stdout.txt:·"00000005↵
would you please guide what is going wrong with my code? Thanks a lot in advance.