First Word :- Given a sentence S containing space-separated words, write a program to print the first word among the words in the sentence S

PHOTO EMBED

Mon May 22 2023 14:11:52 GMT+0000 (Coordinated Universal Time)

Saved by @codewithakash

given_word = input()

first_word = ""

for char in given_word:
    if char == " ":
        break
    else:
        first_word += char

print(first_word)
content_copyCOPY

Step 1: Read the input sentence First, we need to read the input sentence S. We can use the input() function to read the input. Step 2: Initialize an empty string for the first word Next, we need to create an empty string called first_word to store the first word of the input sentence. Step 3: Iterate through the characters in the input sentence Now, we will use a for loop to iterate through each character in the input sentence. If the character is a space, we break the loop, as we have found the first word. If the character is not a space, we add it to the first_word string. Step 4: Print the first word Finally, we print the first_word string, which contains the first word of the input sentence.