<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Slope Calculator</title>
    <description>The latest articles on DEV Community by Slope Calculator (@slopecalculator).</description>
    <link>https://dev.to/slopecalculator</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4283147%2F9996ce52-75e5-4825-8f55-c23ff759bc31.PNG</url>
      <title>DEV Community: Slope Calculator</title>
      <link>https://dev.to/slopecalculator</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/slopecalculator"/>
    <language>en</language>
    <item>
      <title>Slope Calculator Guide: Formula, Examples and Python Code</title>
      <dc:creator>Slope Calculator</dc:creator>
      <pubDate>Fri, 04 Dec 2026 16:09:52 +0000</pubDate>
      <link>https://dev.to/slopecalculator/slope-calculator-guide-formula-examples-and-python-code-2lcn</link>
      <guid>https://dev.to/slopecalculator/slope-calculator-guide-formula-examples-and-python-code-2lcn</guid>
      <description>&lt;p&gt;`Slope tells you how steep a line is and which direction it leans. It appears in algebra, road design, roofing, ramps and data analysis.&lt;/p&gt;

&lt;h2&gt;
  
  
  The slope formula
&lt;/h2&gt;

&lt;p&gt;Slope (m) is the vertical change (rise) divided by the horizontal change (run):&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;m = (y2 - y1) / (x2 - x1)&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Worked example&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;Take the points (2, 3) and (6, 11).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rise: 11 - 3 = 8&lt;/li&gt;
&lt;li&gt;Run: 6 - 2 = 4&lt;/li&gt;
&lt;li&gt;Slope: 8 / 4 = 2&lt;/li&gt;
&lt;li&gt;y-intercept: 3 - (2 × 2) = -1&lt;/li&gt;
&lt;li&gt;Equation: y = 2x - 1&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Four types of slope
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Positive&lt;/td&gt;
&lt;td&gt;Line rises from left to right&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Negative&lt;/td&gt;
&lt;td&gt;Line falls from left to right&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Zero&lt;/td&gt;
&lt;td&gt;Horizontal line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Undefined&lt;/td&gt;
&lt;td&gt;Vertical line (run is 0)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Slope, angle and percent grade
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Angle = arctan(m)&lt;/li&gt;
&lt;li&gt;Percent grade = m × 100&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A road rising 3 m over a horizontal 60 m has a slope of 0.05, a 5% grade and an angle of about 2.86°.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where slope is used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ramps:&lt;/strong&gt; US ADA standards set a maximum running slope of 1:12 for ramps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Roofs:&lt;/strong&gt; A 6:12 pitch is a slope of 0.5, about 26.57°.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data:&lt;/strong&gt; The slope of a trend line shows how fast one value changes with another.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Calculate slope in Python
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;`python&lt;br&gt;
import math&lt;/p&gt;

&lt;p&gt;def slope(x1, y1, x2, y2):&lt;br&gt;
    if x1 == x2 and y1 == y2:&lt;br&gt;
        raise ValueError("The two points must be different")&lt;br&gt;
    if x1 == x2:&lt;br&gt;
        return None, 90.0  # vertical line&lt;br&gt;
    m = (y2 - y1) / (x2 - x1)&lt;br&gt;
    return m, math.degrees(math.atan(m))&lt;/p&gt;

&lt;p&gt;print(slope(2, 3, 6, 11))  # (2.0, 63.43...)&lt;br&gt;
`&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Subtracting the points in a different order on top and bottom&lt;/li&gt;
&lt;li&gt;Dividing run by rise&lt;/li&gt;
&lt;li&gt;Mixing units, such as metres and centimetres&lt;/li&gt;
&lt;li&gt;Calling a vertical line's slope zero&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Check your answer
&lt;/h2&gt;

&lt;p&gt;I run a free &lt;a href="https://slopecalculator.org" rel="noopener noreferrer"&gt;slope calculator&lt;/a&gt; that shows step-by-step working and a graph, so you can compare it with your hand calculation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was created with the help of AI.&lt;/em&gt;`&lt;/p&gt;

</description>
      <category>maths</category>
      <category>python</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
