I need help with python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

27th Apr 2021, 8:46 PM
Lara Simić
Lara Simić - avatar
2 Answers
+ 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
27th Apr 2021, 9:26 PM
YUGRAJ
+ 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
28th Apr 2021, 1:24 AM
noteve
noteve - avatar