When you want to use variables outside your function for use within your function, you will have to use the keyword global. This will allow you to use variables declared outside of a function. It will even override the variables inside the function if they have the same name. You can also use it to access the variables inside the…