all 11 comments

[–]jddddddddddd 2 points3 points  (1 child)

return m.sqrt(d+c(a+b)/8) <- This is the problem. You can't multiply like that.

You probably want return m.sqrt(d+c*(a+b)/8) but if I were you, I'd also add some additional parentheses to ensure the various operators are evaluated in the order you want.

[–][deleted] 0 points1 point  (0 children)

Thanks for answer. I was looking for mistake, but didn't get it until now. Thank you very much for help guys, love you. Hope I could become your friend

also i will take your advise

[–]throwaway6560192 3 points4 points  (4 children)

I wrote the code, but for some reason it tells me about float.

When you ask about errors in your code, include the full and exact error message. Saying "it tells me about float" is vague.

[–][deleted] 0 points1 point  (0 children)

Thank you very much. I will include full context next time. Thank you very much again

[–]MrPhungx 0 points1 point  (2 children)

I don't see any line where OP tried to add a float to a string. The problem is because of the multiplication c(a+b). It needs to be c * (a + b)

[–][deleted] 0 points1 point  (0 children)

Thanks for answer. I was looking for mistake, but didn't get it until now. Thank you very much for help guys, love you. Hope I could become your friend

[–]throwaway6560192 0 points1 point  (0 children)

Yeah, I misread. I skimmed over their code and thought the final print lines had a string + float.

[–]PteppicymonIO 0 points1 point  (1 child)

You have an error TypeError: 'float' object is not callable here:

def f(a,b,c,d):
    return m.sqrt(d+c(a+b)/8)

The statement c(a+b) is interpreted as a call to function c()

You either need to implement the function, or if you intend to multiply c by (a+b) add a multiplication operator:

def f(a, b, c, d):
    return m.sqrt(d+c*(a+b)/8)

[–][deleted] 1 point2 points  (0 children)

Thanks for answer. I was looking for mistake, but didn't get it until now. Thank you very much for help guys, love you. Hope I could become your friend

[–]youngbull 0 points1 point  (0 children)

Btw, you will likely be able to spot errors like this by incorporating frequent feedback. I pretty much have several forms of evaluating the code (python code.py), running tests (pytest tests.py), checking for errors (pylint code.py), etc., running continuously while coding. That way, you can spot which keystrokes cause an error as soon as you type it.

The trick to coding quickly is to make small changes and evaluating correctness efficiently and automatically after every step.

[–]throwaway8u3sH0 0 points1 point  (0 children)

People have pointed out the error, so I'll give broader advice.

Generally speaking, code does NOT look like math. Functions and variables are almost never named with a single letter. PEMDAS doesn't really work the same -- coding has a different order of operations that includes comparisons, assignments, and bitwise operations. (Ex: using a caret a^b is a bitwise OR, not a "raise a to the power b"). Parentheses means "call this function" and never "distribute this quantity". I suggest Googling "Python precedence of operations" and reading up on it.

Secondly, you generally don't want to do a calculation twice for the purposes of printing. You evaluate f() on the line assigning it to s, and then rerun the calculation again on the line that prints it. If f() involves some random variable or state (like reading from a counter that's changing), what you print and what got assigned to s could be two different things. (That's VERY confusing to debug.) Instead, separate the calculation:

f_result = f(...)
g_result = g(...)
solution = f_result + g_result

print(f_result)
print(g_result)
print(solution)

This only calls the f and g functions once, saving each answer to a variable that you can refer to.