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

Huijuan Pei
Huijuan Pei
1,537 Points

Why does it appear as syntax error ?

Why does it appear as syntax error when I try to run the following code?

try: a=int(input("Give me a number: ") except ValueError: print("This is not a number!") else: print('Hi'*a)

2 Answers

Dylan Rainwater
Dylan Rainwater
15,537 Points

Hi Huijuan,

It appears that you are missing a second closing parenthesis around your input. It should be:

try: 
    a = int(input("Give me a number: ")) 
except ValueError: 
    print("This is not a number!") 
else: 
    print('Hi'*a)
Huijuan Pei
Huijuan Pei
1,537 Points

Thanks Dylan. I looked at it for 30 minutes, couldn't spot the missing parenthesis. Guess I need a pair of glass for better coding :)

Dylan Rainwater
Dylan Rainwater
15,537 Points

No problem! It's always easy to miss a parenthesis here or there.