Python for Kids, Class 9: Error Handling

Published: 24 January 2024
on channel: Téa's Academy
9
like

Hey there, code explorers! Don't forget to check our last lesson. Pause the video whenever you want, and make sure you try out all the cool examples we're exploring in this class (see instructions below). Practice makes coding even more awesome! If you're hungry for more Python adventures, check the rest of the videos in this playlist.

In this class you will learn about:
• Types of errors: syntax, runtime, and logical
• Try-except blocks and their syntax
• Handling specific exceptions
• Debugging code with print statements

Here's the code from today's class! Feel free to explore it, tweak it, and make it your own coding masterpiece. Happy coding.

#####
try:
candies = int(input("Enter the number of candies you have: "))
friends = int(input("Enter how many friends to share with: "))
result = candies / friends

print(f"Each friend gets {result} candies!")

except ZeroDivisionError:
print("Oops! You can't share with zero friends. Try again!")

except Exception as e:
print(f"Oops! An error occurred: {e}")

finally:
This block always runs, say thank you!
print("Thanks for sharing with friends")

#####

Now, head to W3Schools' Python page: Python Playground (https://www.w3schools.com/python/tryp.... Just type your code or copy and paste from the examples above in the left box and hit the magic 'Run' button!


On this page of the site you can watch the video online Python for Kids, Class 9: Error Handling with a duration of hours minute second in good quality, which was uploaded by the user Téa's Academy 24 January 2024, share the link with friends and acquaintances, this video has already been watched 9 times on youtube and it was liked by like viewers. Enjoy your viewing!