+ 1
I need help with python
How do I write a program that prints on which place a letter in an inputted word is placed? For example, in a word ARROW, a letter W is on the 5th place. It shoud go like: m=input('enter a word: ') And I think I should use a while loop then?
2 ответов
+ 1
Yeah you think right just run a while loop
while i<len(word)
And check the current index if it is same as character then print that index and then break from the loop
+ 1
You can use the str.index(char) method to find the index of a character in a string or a list. Then just add 1 (because indexing starts with 0).
Example:
word = "ARROW"
letter = "W"
print(word.index(letter) + 1)
>> 5