CBSE Class 12 Computer Science Question 4 of 42

Solved 2024 Sample Question Paper CBSE Class 12 Computer Science (083) — Question 4

Back to all questions
4
Question

Question 4

Select the correct output of the code:

s = "Python is fun"
l = s.split()
s_new = "-".join([l[0].upper(), l[1], l[2].capitalize()])
print(s_new)
  1. PYTHON-IS-Fun
  2. PYTHON-is-Fun
  3. Python-is-fun
  4. PYTHON-Is -Fun
Answer

PYTHON-is-Fun

Reason — The code initializes a string variable s with the value 'Python is fun'. It splits the string into words using split() method, then converts the first word to uppercase ('PYTHON') using indexing and the upper() method, and capitalizes the third word ('Fun') with the capitalize() method. It then joins the modified words with a hyphen ('-') as the separator using the join() method and prints the result.