Given a word W as input, write a program to print the unique character in the word, in the order of their occurrence
Note: consider lower and upper case letters as different
Input
The input is a single line containing as word W
Output:
The out should be a single line containing space- separated character
sample input: MATHEMATICS
sample Output: M A T H E I C S
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
print("INPUT:")
#prompt the user to enter a string
mystring = input("\nEnter a word: ")
#declare a list to store all the characters of the word
my_list = []
#add the characters of the word in the list
for i in mystring:
my_list.append(i)
#check the characters that appear once in the word and print them
print("\nOUTPUT:\n")
for element in my_list:
count = 0;
for i in range(0,len(my_list)):
if element == my_list[i]:
count = count+1;
if count == 1:
print(element, end=" ")
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment