FIX: Python runtime error

by Radu Tyrsina
Radu Tyrsina
Radu Tyrsina
CEO & Founder
Radu Tyrsina has been a Windows fan ever since he got his first PC, a Pentium III (a monster at that time). For most of the kids of... read more
Affiliate Disclosure
  • A run-time error happens when Python understands what you are saying, but runs into trouble when following your instructions.
  • You need to know that Python runs the program in two steps.
  • Not only Python features runtime errors and if you stumble across one, check our Runtime Errors Hub.
  • We wrote extensively about developer tools like Python. Go to our Developer tools Hub.
How to fix Python runtime error
To fix various PC problems, we recommend DriverFix:
This software will keep your drivers up and running, thus keeping you safe from common computer errors and hardware failure. Check all your drivers now in 3 easy steps:

  1. Download DriverFix (verified download file).
  2. Click Start Scan to find all problematic drivers.
  3. Click Update Drivers to get new versions and avoid system malfunctionings.
  • DriverFix has been downloaded by 0 readers this month.

Programming is pretty fun but at some point, when you try to run the program, unfortunately, and inevitably, errors will show up. So, causing, understanding, and fixing errors is an important part of programming.

There are three major types of error that you can get in Python but here we will talk about how to solve Python runtime errors.

A run-time error happens when Python understands what you are saying, but runs into trouble when following your instructions.

How can I fix Python runtime error?

So you’ve written everything correctly, in other words, your syntax is correct, but Python still doesn’t understand what you’re saying. Let’s have a simple example of a Python runtime error:

  • print(solution)

If you try to run this simple line, you will receive a runtime error simply because you didn’t define the solution variable. The line doesn’t have sense.

To understand better that conundrum, let’s make an association with English grammar. Let’s take this sentence for instance.

  • Please eat the door.

Grammatically, there is absolutely no problem with this sentence. Everything is there, we have all the syntax elements correct.

But when you are trying to understand the sentence, when you piece up the words, it doesn’t make sense because you know you can open and close the door, even shut it or taking it out but eating it?

In programming, this will be called a run-time error because it shows up before you start the program. There are a few types of runtime errors. In this article, you will learn how to solve them.

1. Use an undefined variable or function.

This can also occur if you use capital letters inconsistently in a variable name:

callMe = “Brad”

Traceback (most recent call last):
  In line 2 of the code you submitted:
NameError: name 'callme' is not defined

In this case, the program returned the undefined variable error. You defined the variable callMe, but you try to print another variable, callme. You have to use the variables exactly as you define them, case sensitive.

2. Dividing by zero

Guess what? Python cares about math, and in math, dividing by zero makes no sense. 


Traceback (most recent call last):
  In line 1 of the code you submitted:
ZeroDivisionError: division by zero

So this line returns a runtime error as Python can read it properly, but when it comes to executing it, he refuses to do so as it has no mathematical sense.

3. Use operators on the wrong type of data

print(“you are trying to add text and numbers” + 20)
Traceback (most recent call last):
  In line 1 of the code you submitted:
    print("you are trying to add text and numbers" + 20)
TypeError: can only concatenate str (not "int") to str

This line returns the runtime error because you try to add text with numbers, crayons, and oranges, chairs with pigeons, etc. It just doesn’t make sense to perform operations with different types of variables.

You also need to know that Python runs the program in two steps. It first checks the syntax and if the syntax is correct, it goes to the second step of executing the program. That’s where he stumbles on possible runtime errors.

We hope this guide answers all your questions but if you have any others or you run into other problems, please throw them down into the comments section below and we will get back at you ASAP.

idee restoro Still having issues? Fix them with this tool:
  1. Download this PC Repair Tool rated Great on (download starts on this page).
  2. Click Start Scan to find Windows issues that could be causing PC problems.
  3. Click Repair All to fix issues with Patented Technologies (Exclusive Discount for our readers).

Restoro has been downloaded by 0 readers this month.

Frequently Asked Questions

  • The fastest way to fix any runtime errors is to simply install a dedicated runtime error fixer.

  • If one of the lines contains a problem like undefined variables, dividing by zero or performing operations with variables of different types, it will return a runtime error.

  • The most simple example is a program with a simple line like print (1/0). If you run it, you will get a ZeroDivisionError: division by zero error, which is a runtime error.

This article covers:Topics: