Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.