In wireless communications, maintaining sufficient signal st…
Questions
In wireless cоmmunicаtiоns, mаintаining sufficient signal strength is essential fоr a stable connection. You are tasked with simulating a network connection process where weak signal strength should raise an exception. Define a custom exception class called WeakSignalError that inherits from Exception. Set the default error message to "Weak signal detected". Write a function connect_to_network(signal_strength): If the signal strength is less than 40, the function should raise the WeakSignalError. If the signal strength is 40 or greater, the function should print "Connection successful." Write a try-except block that: Calls connect_to_network with a test signal_strength value (you can choose any value). Catches and handles the WeakSignalError exception by printing the exception message.