Computer Science, asked by Pavanipriya62, 17 days ago

program to print all the unique characters in a given sentence

Answers

Answered by Equestriadash
1

Co‎de: [in Python language]

\tt s\ =\ in put("Enter\ a\ sentence:\ ")\\l\ =\ list()\\for\ i\ in\ s:\\{\ \ \ \ \ }if\ s.count(i)\ ==\ 1:\\{\ \ \ \ \ }{\ \ \ \ \ }l.append(i)\\print()\\print("The\ unique\ characters\ in\ the\ sentence\ are:\ ")\\for\ i\ in\ l:\\{\ \ \ \ \ }print(i)

Explanation:

We retrieve the sentence using the \tt in put() function and store it into a variable 's'. A list is created to store the unique characters in the sentence. A \tt for loop is initiated to traverse through the characters in the sentence, which also checks if it's unique or not through a conditional statement that checks if its count/occurrence is equal to 1, using the \tt count() method. If it is, it gets added to the list earlier created for the same and the characters are later on printed.

Similar questions