Write a Python program which defines a function named "divide_two_numbers" that accepts two numeric parameters and divides the first parameter by the second. Your divide_two_numbers function must check the second parameter before dividing; if it is zero, raise an ZeroDivisionError exception which includes the string "second parameter was zero!" as a parameter instead of processing the division. Your main function must call your divide_two_numbers function at least twice; one call must use two normal parameters to verify normal operation, the other call must use zero as the second parameter to test your exception code. These calls must be enclosed in a try/except block to handle the ZeroDivisionError exception and print the string parameter if the exception is raised. Sample Output: 5 divided by 2 is 2.5 Error: second parameter was zero! Here is how I called my divide_two_numbers function from my main function, using 5 and 2 for the first call, followed by 5 and 0 for the second: print("5 divided by 2 is " + str(divide_two_numbers(5, 2))) print("5 divided by 0 is " + str(divide_two_numbers(5, 0)))
# do comment if any problem arises
# do thumbs up if it helps
# Code
def divide_two_numbers(a,b):
if b==0:
raise ZeroDivisionError("second parameter was zero!")
return a/b
try:
print("5 divided by 2 is " + str(divide_two_numbers(5, 2)))
print("5 divided by 0 is " + str(divide_two_numbers(5, 0)))
except ZeroDivisionError as error:
print(error)
Screenshot for indentation:

Output:

Write a Python program which defines a function named "divide_two_numbers" that accepts two numeric parameters and...
Python Program
5. Write a Python program in a file named validTime.py. Include a function named string parameter of the form hh:mm: ss in which these are numeric validTime that takes a values and returns True or False indicating whether or not the time is valid. The number of hours, minutes, and seconds must two digits and use a between 0 and 9). The number of hours must be between 0 and 23, the number of minutes and seconds must...
Hello, In Python Enhance the prior assignment by doing the following 1) Create a class that contain all prior functions MyLib # This function adds two numbers def addition(a, b): return a + b # This function subtracts two numbers def subtraction(a, b): return a - b # This function multiplies two numbers def multiplication(a, b): return a * b # This function divides two numbers # The ZeroDivisionError exception is raised when division or modulo by zero takes place...
Write the code in python programming Language String Statistics: Write a program that reads a string from the user and displays the following information about the string: (a) the length of the string, (b) a histogram detailing the number of occurrences of each vowel in the string (details provided below), (c) the number of times the first character of the string occurs throughout the entire string, (d) the number of times the last character of the string occurs throughout the...
please use python
Question 4: Define a function named q40 that accepts a string as a parameter. After verifying that the string includes only includes numeric digits, count the number of even (E) and odd (O) digits. Finally, create a new string made up of these values and their sum. Repeat this process until your end result is a string containing 123 For example, '15327' contains 1 even digit (E-1), 4 odd digits(O-4) and the sum of these is 5...
Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 language:Python
help ASAP
3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...
Define a function named how_many_substr_of_string(...) which receives two parameters, the first parameters is a list with strings (name it listst) and the second parameter is a single string (name it st). The function should return a number, indicating how many of the strings in the list listst are substrings in the string st As an example, the following code fragment: listst = ["a","bc","dd"] st = "abc" res = how_many_substr_of_string(listst,st) print (res) should produce the output: 2 Language Python
Program must be in Python 3.
Write a program that prompts the user to enter two strings and then displays a message indicating whether or not the first string starts with the second string. Your program must satisfy the following requirements. 1. Your program must include a function called myStartsWith that takes two string parameters. This function returns True if the rst string starts with the second string and returns False otherwise. 2. Your program must include a main function...
Need in Python! Write a function definition named power that takes two formal parameters which can be assumed to be any numeric type. The first parameter is called base, the second is called exponent. The function should return the result of the base raised to the exponent power. You may not use any Python math library functions inside your function. You may create your own code to test the function in an IDE if you wish. HINT: The exponent operator in...
In Python: Write the definition for a function named avg which accepts two int parameters, and returns the average of the two values Write a statement that calls this function to print out the average of values 11 and 25.