Computer Science, asked by czusha13, 1 month ago

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 Equestriadash
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
Equestriadash: Thank you! <3
Similar questions