WDTPD - Strings

8 questions

Q1
What is the output?
S = "ACE"
shift = 2
T = ""
FOR i = 0 TO len(S)-1
    c = ord(S[i]) - ord("A")
    c = (c + shift) MOD 26
    T = T + chr(c + ord("A"))
NEXT
OUTPUT: T
Q2
What is the output?
S = "HELLO WORLD"
words = 1
FOR i = 0 TO len(S)-1
    IF S[i] == " " THEN
        words = words + 1
    END IF
NEXT
OUTPUT: words
Q3
What is the output?
S = "PROGRAM"
T = ""
FOR i = 0 TO len(S)-1
    IF i MOD 2 == 0 THEN
        T = T + S[i]
    END IF
NEXT
OUTPUT: T
Q4
What is the output?
S = "COMPUTER"
OUTPUT: S[3] + S[0] + S[5]
Q5
What is the output?
S = "ABCDEFGH"
OUTPUT: S[2:5]
Q6
What is the output?
S = "RACECAR"
is_pal = true
FOR i = 0 TO 2
    IF S[i] != S[6-i] THEN
        is_pal = false
    END IF
NEXT
OUTPUT: is_pal
Q7
What is the output?
S = "HELLO"
T = ""
FOR i = len(S)-1 TO 0 STEP -1
    T = T + S[i]
NEXT
OUTPUT: T
Q8
What is the output?
S = "BANANA"
count = 0
FOR i = 0 TO len(S)-1
    IF S[i] == "A" THEN
        count = count + 1
    END IF
NEXT
OUTPUT: count