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
Chemistry,
2 months ago
English,
2 months ago
Math,
4 months ago
Accountancy,
4 months ago
Biology,
11 months ago
India Languages,
11 months ago