This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Simple python code wont work. I cant tell why. I am new to python. Its derivative calculator  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this python code below from this link and was trying to get it to work. Its simple derivative calculator.
https://medium.com/@jamesetaylor/create-a-derivative-calculator-in-python-72ee7bc734a4

The answer should show up as 4. Can someone tell me why it wont work? I am completely new
to python. I created it in Notepad plus and am running from Windows 7 command prompt.
I get no errors but the answer does not show up. Anyone now why? thank you

#--------------begin code-------------
#import math package to allow for more function arguments
from math import*


def f(x):
#type your function after return
return x**2

#For instance f(2) = 4

def derive(function,value):
h = 0.00000000001
top = function(value + h) - function(value)
bottom = h
slope = top / bottom
# Returns the slope to the third decimal
return float("%.3f" % slope)


derive(f, 2)

#---------------end code--------------
 
I'm so happy! And I wish to make this tiny ad happy too:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!