Learn Python by Example Comments

Comments

  • I believe only an if statement will solve this correctly since need to do one or the other, but it doesn't look like if statements are covered in this section :( Minor thing but I had to go find this out somewhere else due to it not being listed here.

    cont...
  • @Kavier, thanks, the challenge has been changed so you don't need an if-statement. (The boilerplate code can be ignored.)

  • why doesn't this work?

    if (a**b >= 2 * b**2 and a**b >= (a*b)**2) {
    return True;
    }
    else return False;

  • That's not the if-statement in python. Either peak ahead to control flow or solve the problem without an if-statement.

  • The correct code is:
    if (a**b >= 2*b**2) and (a**b >= (a*b)**2):
    return True
    else:
    return False

  • i think that the problem statement points to decision making , so IF construct is implied , but since it is not yet the time for control flow i used this code and it worked fine :
    cond1 = a ** b >= 2 * b * b
    cond2 = a ** b >= (a * b) ** 2
    return(cond1 and cond2)

  • What is the answer please of this challenge

  • Answer added.

  • I get the following compile error:

    Traceback (most recent call last):
    File "", line 1, in
    File "/usr/lib/python2.7/py_compile.py", line 117, in compile

    cont...
  • @Iavor, you probably mean ==.

  • Thank you, I somehow missed that.

  • for n in ar:
        if n%3 == 0:
            print("no3",end=" ")
        else:
            print(n,end=" ")
    

    It works on my computer interpreter, but at here got a syntax error,SyntaxError: invalid syntax.

  • def do_stuff(ar):
    #print array if you want:
    str1 = ""
    for n in ar:
    if n%3 == 0:
    str1 = str1 + "no3"+" "
    else:
    str1 = str1 + str(n) +" "
    print(str1)
    A correct but ugly answer.

Contact Us
Sign in or email us at [email protected]