WAP that asks the user for a string 's' and a character 'c',and then prints out the location of each character 'c' in string 's' .
Answers
Answered by
10
The following cσdes have been written using Python.
s = input("Enter a string: ")
c = input("Enter a character: ")
print()
print(s.index(c), "is the location of", c, "in", s + ".")
- index() is a method that returns the index position of the specified argument in the variable it's used with. It can even be used to find an element in a list.
An example:
>>> l = ["a", "b", "c", "d"]
>>> l.index("b")
1
Anonymous:
Awesome Diddu! :D
Similar questions
Music,
18 days ago
Hindi,
18 days ago
Math,
18 days ago
Math,
1 month ago
Accountancy,
1 month ago
Biology,
7 months ago
India Languages,
7 months ago