Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics Functions and Looping Expecting Exceptions

Code from outside the house

Can I pass a code here and understand how it's solved Because I tried, but I couldn't

https://w.trhou.se/onnoqlc0uv

5 Answers

Try to give some context, I absolutely did not understand anything you said, what context is outside the house.? However, I checked the forks snapshot, It seems you want to insert a try/except block to ignore the IndexError. In that case, just use pass.

students = [('Timmy', 95, 'Will pass'), ('Martha', 70), ('Betty', 82, 'Will pass'), ('Stewart', 50, 'Will not pass'), ('Ashley', 68), ('Natalie', 99, 'Will pass'), ('Archie', 71), ('Carl', 45, 'Will not pass')]
passing = {'Will pass': 0, 'Will not pass': 0}

for tup in students:
  try:
    if tup[2] == 'Will pass':
        passing['Will pass'] += 1
    elif tup[2] == 'Will not pass':
        passing['Will not pass'] += 1
  except IndexError:
    pass

If this is not the solution, Please provide some details on the problem or instructions.

P.S: what's the source of this code challenge?

Code from outside the house It's just an address. And the source I've been reviewing. In this link.

https://runestone.academy/runestone/books/published/fopp/Exceptions/intro-exceptions.html?highlight=exception%20handling%20python

Thank you for your help. I'm going to try hard to get the lessons back and understand again. Thank you again.

👍. If you like reading, check out "Automate the boring stuff with Python" and "Python Crash Course"

https://w.trhou.se/jb9l0ltz55

ok plz i solve this code too but get fail

Bro, why don't you let me solve every challenge you encounter lol 🤣🤣, I mean like what's the point of learning by trial and error right? Since these challenges are not of TreeHouse, here you go.

nums = [5, 9, '4', 3, 2, 1, 6, 5, '7', 4, 3, 2, 6, 7, 8, '0', 3, 4, 0, 6, 5, '3', 5, 6, 7, 8, '3', '1', 5, 6, 7, 9, 3, 2, 5, 6, '9', 2, 3, 4, 5, 1]

plus_four = []


for num in nums:
  try:
    plus_four.append(num+4)
  except TypeError:
    plus_four.append("Error")

Hear me out, brother, you need to solve challenges on your own to solidify programming concepts in your brain, If you keep asking for solutions, it will probably get you nowhere.

If you are struggling to solve a challenge, re-watch or understand the concepts again, if it takes 100 tries, do it, you will eventually overcome that hardship. Read online, what concepts you don't get, ask about the concepts rather than asking for a direct raw solution. For this solution, I recommend you understand what it is, and write it down, play with it, understand what's going on in the solution.

Sometimes I spent days trying to solve a challenge, but I never try to ask for a direct solution. Take programming strong and easy, go for the long run instead of the short run.

Brother, I don't want you to solve the challenge I'm studying. I sent you the link just to give me your opinion. Didn't you notice I was telling you I was trying? I know you're right. Honestly, you're right, and thank you for the advice. But believe me, I just want a feedback. Give me a note. It's just.

thanks for help me from my heart

In that case, you should point out the issue you're facing, or ask for direction. Anyways, appreciate the feedback👍✌

Thank you again, dear brother. I've learned something important from you. Which is patience. and perseverance in learning more