Python Forum
Help with conditions in loops
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with conditions in loops
#1
Given a sequence of integer numbers ending with the number 0. Determine the length of the widest fragment where all the elements are equal to each other.

The following code works. However, if I un-indent the "if statement" in red, some cases do not work. I don't see how this should affect how the program operates.
n, k = int(input()), int(input())
streak1, streaksum = 1, 1
 
while k != 0: 
    if n == k:
        streak1 += 1

        # Why does unindenting the following change results?
        if streak1 >= streaksum:
            streaksum = streak1     
    else: 
        streak1 = 1
         
    n, k = k, int(input())
 
print(streaksum)
Reply


Messages In This Thread
Help with conditions in loops - by NathanWang - Nov-26-2017, 07:21 PM
RE: Help with conditions in loops - by Mekire - Nov-27-2017, 08:33 AM
RE: Help with conditions in loops - by wavic - Nov-27-2017, 08:54 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020