TEMA

RUNTIME Error in Python

aualam2 preguntado 3 years ago

import math x1=input() y1=input() x2=input() y2=input() x1=float(x1) y1=float(y1) x2=float(x2) y2=float(y2) X=math.sqrt(pow(x2-x1,2)+pow(y2-y1,2)) print('{0:.4f}'.format(X))

why I got runtime error for above code?

Recuerda no enviar soluciones. Tu mensaje puede ser revisado por nuestros moderadores.

  • RodrigoRocha respondido 3 years ago

    When you do something like this x1=input() the entire line is read. That way x1 will be a string with the value, for instance '1.0 7.0'. Try to change the way you are reading the values. Try something like this:

    
    x1, y1 = map(float, input().split())
    x2, y2 = map(float, input().split())
  • UITS_Bangladeshi_Smart_Boy respondido 3 years ago

    The second type of error is a runtime error. A program with a runtime error is one that passed the interpreter’s syntax checks, and started to execute. However, during the execution of one of the statements in the program, an error occurred that caused the interpreter to stop executing the program and display an error message. Runtime errors are also called exceptions because they usually indicate that something exceptional (and bad) has happened.

    • Misspelled or incorrectly capitalized variable and function names
    • Attempts to perform operations (such as math operations) on data of the wrong type (ex. attempting to subtract two variables that hold string values).