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!