This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

Posts: 19
  • 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.

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--------------
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!