Alright, this is my code for ps3 problem 1, and I don't like that double nested ifs. Can anyone suggest me a way to avoid this? http://www.ideone.com/Oq7Mr
You can use a "for in range" statement instead of the first "if". I'll attach my code (which didn't use the "find" function at all...not sure if I was compelled to do so or not....)
Nice! Two different ways to do it, 2 that work quite effectively. Well, I thought I was going to post mine. :( But there is a bug it seems, unfound until now.
If they bother you you could use an "and" and an "elif"... if found == -1 and point == 0: "do whatever" elif .....
http://dpaste.com/572894/ it is quite similar to yours but esentially the difference is that I used a list. (bug fixed).
or this: if point - found = -1: "do whatever" elif found == -1 and point != 0: "do whatever else"
Neat solutions. Since I'm already using find anyway, I'll try out Joz's way. BTW black, when I tried your first solution, it gave me a infinite loop. :P
Not sure how my first answer would give you an infinite loop... It works fine when I used it. http://dpaste.com/574570/ but in reality there was nothing wrong with your nested "ifs" to begin with.. just giving you an alternative you requested:)
Nvm, it's because of this line in my original else clause, point = found + 1 That, and a badly implemented if/else. So my bad really :P Thanks.
Join our real-time social learning platform and learn together with your friends!