Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Catch an Error | Handling Structure
/
Error Handling in Python
セクション 1.  3
single

single

bookChallenge: Catch an Error

メニューを表示するにはスワイプしてください

Now, let's handle the error for the first time.

You should handle this error:

123
from math import sqrt sqrt(-4) # ValueError
copy

Since finding the square root of a negative number is not possible (according to mathematical concepts), performing this operation in Python is not feasible. The interpreter takes this into account and raises a ValueError with the following message: math domain error.

タスク

スワイプしてコーディングを開始

Now, you need to complete the following points:

  1. Define the code block where an error is expected.

  2. Catch this error and print the following string:
    "The ValueError was raised!"

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  3
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt