Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Dorota Parzych
Dorota Parzych
5,706 Points

code problem-syntax error

num = input("Please enter number: ")

def how_big(number): if number <= 10 print("za malo") else number > 11 print("za dużo") elif number == 11 print("Idealnie")

how_big(num)

Inline 4 there is a syntax error - don't know how to fix it

2 Answers

See the first example here. It is close to what you are trying to do. Notice:

  • if, elif, else statements end with a colon
  • else comes last and has no condition. It is what runs when all other conditions are false
  • the input is converted to an integer before being compared to other numbers
Dorota Parzych
Dorota Parzych
5,706 Points

so now it looks like this... num = input("Please enter number: ")

def how_big(number): if int(number) <= 10: print("not enough") elif number == 11: print("perfect") else : print("too much")

how_big(num)

Generally, it works but when I type 11 it shows me that it is too much - why and how to fix that?

Convert number to int before passing to the function. This can be done with the input:

num = int(input("Please enter number: "))

def how_big(number):
  if number <= 10:
    print("not enough")
  elif number == 11:
    print("perfect")
  else :
    print("too much")

how_big(num)