Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Derivative operation
#1
print('Now you are creating your function, when finished type Break')

def f(x):
    total=0
    a=0
    b=0
    while a!='Break' or b!='Break':
        a=input('Enter the coefficient of X:')
        b=input('Enter the power of X:')
        if a=='Break' or b=='Break':
            return total 
            break
        else:
            c=int(a)*x**int(b)
            total = total+c
        
e=0.00001
x=int(input('Enter the X value:'))
r= f((x+e)-f(x))/e

print(r, 'is the value of derivative', 'f(x)','for the X value of',x)
Purpose of this code is it creates a function from the inputs by the user and finds the value of its derivative for a X value again input by the user.
The problem is that when I type Break to a or b input while loop doesn't break.
I would appreciate any suggestion or help.
Thank you in advance.
Reply
#2
The break doesn't happen because return total stops the loop.
It does work its just that it might not seem to because the function f is called twice.
you 'Enter the X value:' it goes into the first f loop you type Break to one of the inputs,
it then goes into the 2nd f loop , you have to type Break to one of the inputs again to exit.
Reply
#3
(May-06-2019, 09:33 PM)Yoriz Wrote: The break doesn't happen because return total stops the loop. It does work its just that it might not seem to because the function f is called twice. you 'Enter the X value:' it goes into the first f loop you type Break to one of the inputs, it then goes into the 2nd f loop , you have to type Break to one of the inputs again to exit.
So I have to define the same function twice for f(x) and for f(x+e) right? Is there any way to define both functions together
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Derivative function Irv1n 1 1,884 May-01-2021, 10:54 AM
Last Post: Larz60+
  Unexpected output: symbols for derivative not being displayed saucerdesigner 0 2,044 Jun-22-2020, 10:06 PM
Last Post: saucerdesigner

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020