Computer Science, asked by adityabatra22, 27 days ago

Write a function: def solution (S) that, given a string S of letters "L" and "R", denoting the types of shoes in line (left or r right

Answers

Answered by Equestriadash
6

The following co‎des have been written using Python.

\tt d ef\ solution(s):\\{\ \ \ \ \ }rc\ =\ 0\\{\ \ \ \ \ }lc\ =\ 0\\{\ \ \ \ \ }fc\ =\ 0\\{\ \ \ \ \ }for\ i\ in\ s:\\{\ \ \ \ \ }{\ \ \ \ \ }if\ i\ ==\ 'R':\\{\ \ \ \ \ }{\ \ \ \ \ }{\ \ \ \ \ }rc\ =\ rc\ +\ 1\\{\ \ \ \ \ }{\ \ \ \ \ }elif\ i\ ==\ 'L':\\{\ \ \ \ \ }{\ \ \ \ \ }{\ \ \ \ \ }lc\ =\ lc\ +\ 1\\{\ \ \ \ \ }{\ \ \ \ \ }if\ rc\ ==\ lc:\\{\ \ \ \ \ }{\ \ \ \ \ }{\ \ \ \ \ }fc\ =\ fc\ +\ 1\\{\ \ \ \ \ }print(fc,\ "is\ the\ total\ number\ of\ shoes\ in\ line.")

We can create user-built functions using \tt d ef. S represents the string. We assign rc to represent the number of 'R's and lc to represent the number of 'L's. fc represents the number of 'R's and 'L's collectively. Appropriate conditional statements are given to retrieve the counts of 'R's and 'L's and the final output is printed.

Similar questions