BaşlayınÜcretsiz Başlayın

Avoiding errors

In the video, you saw a couple of approaches for error handling that can be applied to custom functions.

In this exercise, you'll test out one of the approaches that avoids raising an error, printing a helpful message if an error occurs, but not terminating the script.

Bu egzersiz

Intermediate Python for Developers

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Use a keyword allowing you to attempt to run code that cleans text.
  • Use another keyword that prints a helpful message if an error occurs when calling the clean_text() function.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

def clean_text(text):
  # Attempt to clean the text
  ____:
    return text.replace(" ", "_").lower()
  # Run this code if an error occurs
  ____:
    print("The clean_text() function expects a string as an argument, please check the data type provided!")
    
clean_text(187)
Kodu Düzenle ve Çalıştır