Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

What are RuntimeErrors in Python?

In the code below

a = raw_input('Enter a number:')
b = raw_input('Enter a number:')
c = a*b
print c

if I enter any two integers at prompt, I get the following output

Enter a number:7
Enter a number:8
Traceback (most recent call last):
  File "C:/Users/TutorialsPoint1/~.py", line 3, in <module>
    c = a*b
TypeError: can't multiply sequence by non-int of type 'str'

What type of error am I getting? Is it runtime error?


1 Answer
Manogna

A syntax error happens when Python can't understand what you are saying. A run-time error happens when Python understands what you are saying, but runs into trouble when following your instructions. This is called a run-time error because it occurs after the program starts running.

A program or code may be syntactically correct and may not throw any syntax error. This code may still show error after it starts running.

The given code can be corrected as follows

a = input('Enter a number:')
b = input('Enter a number:')
c = a*b
print c

The output we get is as follows

"C:/Users/TutorialsPoint1/~.py"
Enter a number:7
Enter a number:8
56

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.