Search code examples
python-3.xstdinsys

what i want is verbal explaination of the code for read or use inputs given by stdin in coding exam in python language


How to read or use inputs given by stdin. For example, there are n poles with different heights. From these n poles, I have to determine whether a square will form or not using any 4 poles.I am provided with inputs of 2 line strings. 1st line gives the number of poles, 2nd line gives the height of poles. like below Inputs

8

2 4 3 2 2 4 2 2

output

YES

explanation: there are 4 poles with same height so square can be formed.

if I have to define function which takes 1 parameter as input. How should use this parameter eg. def Determinesquare(parameter):


Solution

  • Here's how you do it in python.

    no_of_poles=int(input())
    
    #store all the heights into a list for easy access
    heights=list(map(int,input().split()))
    

    and then proceed with solving the problem.