Answer:
def texted():
text= input("Enter Text: ")
text = text.lower()
nlist = ' '
for char in text:
if char.isalnum() == True:
if char not in nlist:
nlist = nlist + char
nlist = sorted(nlist)
print(nlist)
return;
texted()
Explanation:
Step 1:
Define the function, i.e give it a name.
<em>def texted():
</em>
<em />
Step 2:
Prompt the user to input a string i.e Text
<em>text= input("Enter Text: ")
</em>
<em />
Step 3:
use the lower() string method. it is a method in python used to convert uppercase string characters to lower case.
<em>text = text.lower()
</em>
<em />
Step 4:
Declare an empty string variable that will be used to store the characters while sorting.
<em>nlist = ' '
</em>
<em />
Step 5:
<em>for char in text:
</em>
<em> if char.isalnum() == True:
</em>
<em> if char not in nlist:
</em>
<em> nlist = nlist + char
</em>
<em />
-Use a for loop to iterate through all the characters in the text.
-<em>.isalnum() </em>is a method in python that returns true if a character is an alphabet or a number.
The first if statement checks if it is an alphabet or a number and if it passes as true, it passes that alphabet or number to the next if statement.
- The second if statement checks if the character is not already in the list, if it is in the list it would not add it a second time.
If the character is not in the list, it adds the character to the list.
Step 6:
- sorts the list, i.e arranges the list in an alphabetical order.
- prints out the list, i.e produces an output of the list to your computer screen.
<em>nlist = sorted(nlist)
</em>
print(nlist)
- <em>texted() this is used to call the function. </em>