0

Basic def and if python question

I have written some pretty basic code here just trying to get it to tell me if x squared + 4 is less than 20 for a given x. ************************** 1 def f(x): 2 print((x**2) + 4) 3 4 x = 2 5 6 if f(x) < 20 7 print("true") ************************** It keeps telling me syntax error on line 6 which is the “if” line and pointing to the “20” though that sometimes changes. I’ve tried different combinations of spaces and notations, I began with “if f(4) == 20 print(“true”)” And changed it from there but still haven’t got a true back. Thanks guys!

6th Dec 2019, 8:01 PM
James Wilkinson
James Wilkinson - avatar
2 Réponses
6th Dec 2019, 8:04 PM
Diego
Diego - avatar
+ 1
def f(x): return x**2 + 4 x = 2 if f(x) < 20: print("true")
6th Dec 2019, 8:27 PM
rodwynnejones
rodwynnejones - avatar