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 Functions and Looping Raising Exceptions

aditya verma
aditya verma
1,853 Points

Comparing try/raise with while loop to handle errors

Once we understand the while loop, which is better to use, try or while for example, i did check splitting code with while

import math
def split_check(total, number_of_people):
    return math.ceil(total/number_of_people)
total=int(input('what is the total ')) 
number_of_people=int(input('how many people '))
while total <= 0 or number_of_people<=1:   
        print('enter correct number')    # until you dont enter correct value, code keeps prompting
        total=int(input('what is the total ')) #note the space
        number_of_people=int(input('how many people '))
split_check(total, number_of_people)

isn't this better in functionality than what we did with try/raise/except? Thanks

3 Answers

I feel absolutely lost. I've taken HTML, CSS, JavaScript, Digital Literacy, and Business courses, as well as a little Design plus the little Machine Learning course. Something is very different about this specific Python course. All other courses give you the sense of progression. I was in the top 100 on the leaderboard last week, I'm like #19 right now.

I have a feeling the lessons are sort of "bouncing around" a little too much in beginning Python. One minute I'm learning functions, the next minute we get focused on Syntax errors, the next minute we are learning vocabulary words that we end up not using, then we will be shown something and told "not to worry about this", and then we end up on a question that most people seem to get "stuck" on. One of the code tests I just did has several dozens questions just since December 2018. I hope I'm wrong and eventually catch on but I can certainly sense something strange about how this course is being taught.

(I'm one of those students who take notes on nearly all content and material on every single video, I always research, I practice, I rewatch videos, etc... so it's not like I'm learning incorrectly or something lol)

I haven't got to dictionaries yet, but I noticed that section blows up with "help" posts all day everyday.

IΒ΄ve also been learning a bunch of different languages on a bunch of different sites and usually change up something once i get to a point i donΒ΄t really get and this is starting to be up there.. It has been easy getting up to this point since ive been learning this stuff from elsewhere too but this course does seem to jump around a lot and keeps on making new stuff to learn and not really repeating and giving more examples which i think i would need to understand these better.. Loving this site and the teacher is great but somethings a bit off and going past some subjects a bit too quick..

Michael Casella
Michael Casella
1,358 Points

I feel like the try / raise example is more explicit about what the error is to the end user. The while loop will continually run until the correct answer is given, but it doesn't outline what the error type is. The while loop will only move forward with the correct answer, where as the try/raise will tell the end user why their entry was inaccurate.