ProgrammingModerateSSC CGL Tier 2 · IBPS PO Mains
The string " hello world " is split by the Python-style rule that runs of spaces are treated as one separator and empty pieces are dropped. The procedure below counts the words. What is printed?
The string " hello world " is split by the Python-style rule that runs of spaces are treated as one separator and empty pieces are dropped. The procedure below counts the words. What is printed?
count = number of non-empty pieces after splitting on runs of spaces Print count
- A. 8
- B. 2
- C. 17
- D. 3
Correct answer: B. 2
Splitting on runs of spaces leaves the two words hello and world, so the count is 2. Splitting on single spaces produces empty pieces that inflate the count, the string length is 17, and adding one to the non-empty count gives 3.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- The longest common subsequence (LCS) of "ABCBDAB" and "BDCABA" is computed by the standard table. The procedure below prints its length…
- The number of non-empty substrings of "abcd" (substrings are contiguous pieces, counted by position) is computed by the procedure below…
- The procedure below counts the uppercase letters in the sentence "Hello World From AI". What is printed? count = 0 for each character c if…
- Strings are compared by dictionary order. The procedure below counts how many of ["apple", "mango", "kiwi", "banana", "mangoes"] are…
- A message of digits is decoded by mapping 1 to A, 2 to B, ..., 26 to Z, where a digit string may be split into one- or two-digit groups…
- A polynomial rolling hash of the string "abc" is computed as h = (h 31 + value) mod 1000, starting from h = 0, where value is the position…