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

python exception not working as example

user_string = input("What's your word? ")
user_num = input("What's your number? ")

try:
  our_num = int(user_num)
except:
  our_num = float(user_num)

if not "." in user_num:
  print(user_string(our_num))
else:
  ratio = round(len(user_string) *our_num)
  print(user_string(ratio))

When I try this like the example, the code runs through the questions, but when i give it a number, it just ends and gives me a command prompt.

sorry, the editor (I guess) took out the spaces and lines. Sorry for the format

there's a way to post your code (Check the markdown sheet for clues!)

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You're using parentheses where you should be using brackets. Inside of your print() functions, where you're accessing a member of the string, you should use brackets. Like: my_string[1] instead of my_string(1).

Thanks kenneth