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 Basics (Retired) Things That Count Exceptions

Mine returns command prompt

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))

The above is my code as I copied it from the video. My code does ask the questions, but does nothing with the numbers, therefore it escapes out and I get the command prompt line? What happened?

William Li
William Li
Courses Plus Student 26,868 Points

Can you format your code properly using Markdown code block? It's really hard to read, especially Python code, without proper indentation, it's impossible to understand what goes wrong.

Thanks for the help william. cleared it right up

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Looks like you're using parentheses where you should be using square brackets. This is inside of your if and else blocks when you print(). You're accessing a member of the string and this is done with brackets.

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