What is wrong with this?
It should print every Letter times its Position in the String! But it does not work always. If a letter repeats in the word then we have Problem. What should I do? word = str(input()) for x in word: m = word.index(x)+1 print (x * m)
Ism Familiya , please do not post some code that has no relation to the current question. if you have a coding related question, please create your own post.
Aref Ahmadi , the issue with the current code is that it uses .index(). index() gets always the first occurrence of the searched character in a sequence, so duplicated characters don't get their correct index. instead of this, we can use a variable `ind` that is used as an index: word = str(input()) ind = 1 # <<< use a variable that holds an index for x in word: #m = word.index(x)+1 # not required print (x * ind) ind +=1 # <<< increment index variable
Aref Ahmadi As mentioned by [user id="7235582"]Lothar[/user] , .index() always gets the first occurance of a character in a string and therefore problems arises in case of repeat chars. It is not possible to complete the task without modification
Lothar [user id="4821936"]Sandeep[/user] Thank you guys. That is what I wanted to know. By the way I just found out that I should use Tag to Kind of answering a comment.
word = input() for x in range(len(word)): print (" "*x, word[x], sep="")
Isn't it easier to do this through the counter?
You can do it in your own way, just add a condition when you meet the same symbol. 😎
With all respct, when I ask what is wrong with my code, I mean I want to get to the result with my own aproach. Of course you can solve this Problem in different ways but I want to know if it is possible to solve it in my way.
O problema está na repetição da variável. Aconselho a substituir o X.
Please help me with HTML
What is the mistake here?
Unable to overload +
I have tried every way I could find but still I can't display my local images ..what am I doing wrong?
Pls rectify the errors.
Python list half printed