0

Python has gone mad. My code doesn't work. Although I wrote everything correctly. I have no error. HELP ME PLEASE

https://code.sololearn.com/cLQ04ZHeuG96/?ref=app

28th Aug 2020, 9:38 AM
иван
иван - avatar
8 Antworten
+ 3
Well its counting all letters but only printing the last one becuase firstly the for loop executes with its if block completely checking the value of the last letter of word and returning it as v[n] and after that if block executes which commands it to print. So if you shift the if block in the for loop it will work fine or you can also do one more thing to shorten your code make you print statement goes under for loop if block because you checking the same thing twice.
28th Aug 2020, 12:44 PM
Nihar Buliya
Nihar Buliya - avatar
+ 9
иван , you can write complex code, but you need to be very familiar with the basics of a programming language. You also need to practice by creating codes. With the code you presented, you have moved to a complexity level, that causes problems for you. Start small until you can solve simple problems, than try to improve the code until it works correct. Also try to solve the same task by using more advanced codings. And it's not only to know how to solve a challenge or problem, it's also important to improve the own problem solving ability. Start small and improve yourself with small steps. This takes time, but it's always better to take one step after the other, than tripping over your own feet. All the best success for you!
28th Aug 2020, 8:06 PM
Lothar
Lothar - avatar
+ 8
иван , i did some tests with the code and found a behavior that for each character you input, the loops are running 25 times. so this a issue of the algorithm. there is also an expression: if x==v[n]: that checks if x (a single character of input) is in the alphabet at a certain index. But this can not be done in this way. This expression is also used again in an if clause some lines down, and so on. Allow me to give you a friendly hint: Don't try to "repair" this code. take a sheet of paper and some time to find an other algorithm, that is more straight forward. A general question must be: what should the code produce? Do you need to see the characters in count only if they appear in the input, or should also characters be shown with 0 count if they don't appear in the input? And should only characters and space be counted or also digits and sprcial characters?
28th Aug 2020, 4:55 PM
Lothar
Lothar - avatar
+ 3
Well if you shift the 2nd if block in for loop its showing result for every alphabtes but you might face a problem if the word has repeated alphabets like "Sentence" which has 3 e it will shows everytime the e is iterated
28th Aug 2020, 10:43 AM
Nihar Buliya
Nihar Buliya - avatar
+ 3
Lothar but I don't want to write simpler code. I want to hone my programming skills and understand WHAT THE PROBLEM IS AND HOW TO SOLVE IT. So I could even use the command "count()". But thanks for the advice (◕દ◕)
28th Aug 2020, 6:28 PM
иван
иван - avatar
+ 1
Nihar Buliya but why in my code it only counts the last letter? Can you explain, if not difficult?🙏
28th Aug 2020, 12:15 PM
иван
иван - avatar
+ 1
Nihar Buliya But thank you very much for answering!
28th Aug 2020, 2:40 PM
иван
иван - avatar
0
Nihar Buliya sorry bro, but i don't understand ಠ︵ಠ
28th Aug 2020, 2:39 PM
иван
иван - avatar