'float division by zero' error for Exercise 3 - harrell_c in C2_W4_Assignment

Dear all,

I am new to the community and this is my first post. If I violate any rules please let me know.

I receive ‘float division by zero’ error for Exercise 3 - harrell_c in C2_W4_Assignment. I assume that means my permissible pairs are zero. But I couldnt find the root cause. Are there any ways that someone can help to check my code and see what went wrong?


“Float division by zero” error happens when you attempt to divide a floating-point number by zero, which is not allowed in most programming languages.

Also you can check the code of conduct and the zero tolerance policy to get to know the rules .


You could share screenshot of your error. Codes are not allowed to be posted on public thread.


@Deepti_Prasad, @aryan010204 Many thanks for answering. I found the mistake.

My pleasure feel free to post more queries we are here to help.

Hello Deepti_Prasad,
I’m having a problem also with harrell_c function. Here is a screenshot of the error I encounter.

Hello Ehab,

Your error log is stating you are using a global variable which is not suppose to be recalled inside a function.


A global variable in Python is often declared as the top of the program. In other words, variables that are declared outside of a function are known as global variables.

Global variables can be used by everyone, both inside of functions and outside.

Once you’ve defined a global variable, you can use it from within the module itself or from within other modules in your code. You can also use global variables in your functions. However, those cases can get a bit confusing because of differences between accessing and modifying global variables in functions.

To understand these differences, consider that Python can look for variables in four different scopes:

  • The local, or function-level, scope, which exists inside functions
  • The enclosing, or non-local, scope, which appears in nested functions
  • The global scope, which exists at the module level
  • The built-in scope, which is a special scope for Python’s built-in names.

When you access a variable in that inner function, Python first looks inside that function. If the variable doesn’t exist there, then Python continues with the enclosing scope of the outer function. If the variable isn’t defined there either, then Python moves to the global and built-in scopes in that order. If Python finds the variable, then you get the value back. Otherwise, you get a NameError:

Global variables inside a function
Global variables in your functions and in your code can cause a few undesirable effects. These variables can make your code harder to understand, test, and debug. They can also lead to less maintainable and reusable code. So, you must use global variables with care and control.

One can use e are some neat strategies that you can use to minimize the need for global variables in your code.

Use Global Constants

Perhaps the most intuitive strategy for avoiding global variables is to use global constants. Unlike variables, constants must not change their value during the code execution. So, they promote the safe use of global names


1 Like

Thanks a lot for your help.