Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Homework 4 Conditions and Translation. I'm getting an error in a specific case.

f
felipebarussi (1520 points)
4 8 12
in HW4 by (1.5k points)

So, I've already done the translation and the substitution of the source music. I'm with a string of all of the numbers and symbols already changed into they respective ones. 
I've been able to use this string and by using a for loop to get each element and some if else statements. It was all good, however when two letters are equal but one of them is a sharp or flat, it doesn't return the correct value. 

The if else are the follow: I separed into two section. When the element is equal to # or b and when the element is not equal to any of these.

When the element is equal to any of these, i'm adding a one to a counter n,  if the previous element and the next is different, then, i'm going to add the previous elements, which is going to be the letter, the element itself, wheter a # or a b and the counter itself. After that, I zero the counter. 

When the element is not equal to # or b, i'm going to add to another counter +1, if the next element is different then the present element and is not a # or a b, then i'm going to add to the final string the present element and the counter. After that I zero the counter. 
However the Result(the first line is the base string, the second my result, the third the solution for this test). I don't know why the blue section is different and don't have a idea on how to solve it using the if else statements. 

Thank if you can help me!

 

193 views

2 Answers

AL1990 (28120 points)
3 6 142
by (28.1k points)
edited by
I think your program doesn't evaluate the case in which when the present element is equal to # or b and the previous element and the next are equal to each other.

I would add a check on this case too, it might be a suggestion to work on a list instead of a string and do an intermediate step in which you join # and b to the respective notes.
g
greensimo (1630 points)
0 0 7
by (1.6k points)
I personally find very useful to use print statements. For instance a print line after each loop/if/else statement showing your counters and the character your are assessing. You should be able to monitor if the counters are behaving as expected…it’s a pretty basic way of debugging. If you know how to use the debugger in your idle you can achieve the same.