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
Tim Butler
Courses Plus Student 424 PointsWhat if you entered a float number greater than 1?
What if you entered a float number greater than 1? e.g. 3.5. It has a '.' but 3.5 multiplied by the length of the string would give a number greater than the string length and the program wouldn't be able to find the corresponding letter, right?
3 Answers
Chris Freeman
Treehouse Moderator 68,468 PointsThe code will raise the error IndexError: string index out of range in the statmement user_string[ratio]
You cannot look up an index in a string greater than it's length.
Tim Butler
Courses Plus Student 424 PointsSorry, I thought it would say that automatically. It's in the Python Basics tutorial (exceptions):
https://teamtreehouse.com/library/python-basics/things-that-count/exceptions
Tim Butler
Courses Plus Student 424 PointsThanks for the help Chris. That's what I figured but found it odd that the example given would produce an error.
JoAnna Black
659 PointsIn the video you're talking about, Kenneth does offhandedly mention that the code he's writing is a bit naΓ―ve since it assumes that the user will input something that works within its parameters.
Chris Freeman
Treehouse Moderator 68,468 PointsChris Freeman
Treehouse Moderator 68,468 Pointswhich challenge is this for?