fb pixel

Introduction to Python

  • Profound Academy

    • Status
      • 1
        Input and Output
      • 2
        Variables and Integer Arithmetic
      • 3
        Conditional Operators
      • 4
        Advanced Conditions - Nesting
      • 5
        Types and Variables
      • 6
        Strings
      • 7
        Lists
      • 8
        For Loops
      • 9
        While Loops
      • 10
        continue, break, while...else
      • 11
        String and List methods
      • 12
        Nested Loops
      • 13
        List Comprehension
      • 14
        Tuples and Sets
      • 15
        dict
      • 16
        Functions
      • 17
        Functions 2
      • 18
        Lambda and higher-order functions
      • 19
        Files

  • Infinite loop

    It’s possible to “break out” of the infinite loop with break as well:
    while True:
    	n = int(input())
    	print('The input was:', n)
    	if n == -1:
    		break
    
    print('End of the program!')
    Input
    Output
    10 20 16 8 0 2 -1
    The input was: 10 The input was: 20 The input was: 16 The input was: 8 The input was: 0 The input was: 2 The input was: -1
    As soon as the inputted number is -1, the program stops the loop. We can break the loop at an appropriate time to stop the program from executing an unwanted thing for specific input.

    Challenge

    Given a sequence of numbers, we are interested in how many times is the largest number in the sequence repeated.
    The sequence is given as a stream of integers, and the sequence is terminated as soon as the inputted number is equal to 0. The rest of the input should be ignored.
    The program should output a single integer - the number of times the maximum element in the sequence is repeated.
    Input
    Output
    5 5 1 1 5 3 0 9 11 4 5
    3
    Explanation: The largest number is 5 and it appears 3 times before the sequence is terminated.
     
    To check your solution you need to sign in
    Sign in to continue