-2

I'm trying to understand how functions work, I defined my function with length and area parameters.

Here is the problem: I want to write if area is less than a # then print a string of text.

def rec_area(length, width):     
    area = length * width        
    print(area)                   

    if area : < 25   # Here is the problem, "expected expression"
    print("The area is smaller than expected..")

rec_area(5, 5)    

I tried to put if area: < 25

I also tried if area -= 25

I am lost.

1
  • 3
    this code should give SyntaxError: invalid syntax. If you get any error then you should show it in question (not in comments) as text (not image). And show full error message (full traceback) because there are other usefull information. Maybe visit some other questions to see how others ask questions, and what information they put in question. Commented Sep 28 at 18:07

2 Answers 2

0

Fix:

if area < 25:
    print("The area is smaller than expected..")

note where the : is and the indentation

Check:

https://docs.python.org/3/reference/compound_stmts.html
https://docs.python.org/3/reference/lexical_analysis.html#indentation
https://docs.python.org/3/tutorial/controlflow.html

Sign up to request clarification or add additional context in comments.

Comments

0

When comparing two values by using <, >, ==, !=, <= or >= (sorry if I missed one), you don't need to use:
num1 : < num2

You can just use:
num1 < num2

This is true for at least C, C++, Python and JavaScript, I haven't used other languages

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.