Recent content by Gamerboy

  1. G

    Python codecademy question about indentation/else/return

    I got it. It makes sense now but my head was about to explode haha. the else inside the for loop is executing the first time the if is false. The else should be associated with the for instead of the if. Thanks a lot rgd1101
  2. G

    Python codecademy question about indentation/else/return

    or is it just checking 9 % 2 and then moving on to the else statement when that evaluates to false?
  3. G

    Python codecademy question about indentation/else/return

    and can I deselect that answer as the best one? He apparently missed the same thing I did originally.
  4. G

    Python codecademy question about indentation/else/return

    it should run through and check: x = 9 9 % 2 9 % 3 and at that point it would be true so it wouldn't need to check 4 - 8 right?
  5. G

    Python codecademy question about indentation/else/return

    I understand why the second section in the OP works now. x = 3 bypasses the for loop entirely the way it was written. That should check if 9 % 3 == 0 which would be true so it should return False. Am I missing something else?
  6. G

    Python codecademy question about indentation/else/return

    Now I get another error when I get rid of the x-1. Oops, try again. Your function fails on is_prime(9). It returns True when it should return False. def is_prime(x): if x < 2: return False elif x == 2: return True else: for n in range(2, x): if...
  7. G

    Python codecademy question about indentation/else/return

    Ah that's right. range() stop doesn't include the number it stops at so it wouldn't include 2. So when x = 3 it doesn't get checked. Nice
  8. G

    Python codecademy question about indentation/else/return

    If I understand it correctly it would see if 3 / 2 has a remainder of 0 which of course would return False.
  9. G

    Python codecademy question about indentation/else/return

    How do I put it in code blocks? :p Thanks
  10. G

    Python codecademy question about indentation/else/return

    So I'm going through the codecademy python course and one assignment is to create a function that can determine if a number is prime or not. I don't understand what the difference is between these two examples. The first one doesn't work but the second one does. I get this error message when...
  11. G

    C++ if statement

    Best answer selected by Gamerboy.
  12. G

    C++ if statement

    Never mind I figured it out. I switched if ( x = 100) for if (x == 100). Thanks.
  13. G

    Best non-classroom way to learn to program?

    www.cplusplus.com www.learncpp.com Those are my favorite sites for C++.
  14. G

    C++ if statement

    I wrote this program to practice the if statement. I can't get it to execute the else statement. Regardless of what the user enters it executes the if statement. //A program to let the user entera score and output if the score was perfect. #include <iostream> int main() { using namespace...