fb pixel

Introduction to Python

  • Profound Academy

    • Status
      • 1
        Input and Output
      • 2
        Variables and Integer Arithmetic
      • 3
        Conditional Operators
      • 4
        Advanced Conditions - Nesting
      • 5
        Types and Variables
      • 6
        Strings
      • 7
        Lists
      • 8
        For Loops
      • 9
        While Loops
      • 10
        continue, break, while...else
      • 11
        String and List methods
      • 12
        Nested Loops
      • 13
        List Comprehension
      • 14
        Tuples and Sets
      • 15
        dict
      • 16
        Functions
      • 17
        Functions 2
      • 18
        Lambda and higher-order functions
      • 19
        Files

  • math

    Python built-in functions are very useful for performing generic operations but sometimes more specialized operations are needed. Those are usually packaged in modules. Python is well known for a wide variety of helpful modules and libraries that support many operations out of the box.
    To use modules in python, we need to import them first and use the functions inside of them afterward:
    import math
    
    a = math.sqrt(3)    # Square root of 3 => 1.73205080757
    b = math.ceil(3.4)  # Ceiling function => 4
    c = math.floor(3.4) # Floor function => 3
    d = math.round(3.4) # Round 3.4 => 3
    All the functions in the math module are available through math.FUNCTION_NAME. If one does not want to write math. at the beginning of each function, those functions can be imported at the beginning:
    from math import sqrt, ceil, floor, round
    # from math import *  # Or we can import everything (this is a bad practice)
    
    a = sqrt(3)    # Square root of 3 => 1.73205080757
    b = ceil(3.4)  # Ceiling function => 4
    c = floor(3.4) # Floor function => 3
    d = round(3.4) # Round 3.4 => 3
    The whole list of functions supported by math can be found on the main python website: https://docs.python.org/3/library/math.html
     

    Challenge

    The standard Euclidean distance is defined as . Given two points, calculate their Euclidean distance.
    The input consists of 4 numbers: and coordinates of the first point followed by and coordinates of the second point. The program should output the Euclidean distance between those two points.
    Input
    Output
    3 4 1 0.5
    4.031128874149275
     
    To check your solution you need to sign in
    Sign in to continue