Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from math import e
- from prettytable import PrettyTable
- n = float(input("input: "))
- error = 0.00001
- #print('Error: {:f}'.format(error))
- t = PrettyTable(['n', 'A', 'B', 'sign f(A)', 'sign f(B)', 'C', 'f(C)', '|A-B|< Error', 'Yes/No'])
- for n in range(99):
- a = input('Value of A: ')
- b = input('Value of B: ')
- c = (float(a)+float(b))/2
- fa = pow(math.e,float(a))-pow(float(a),2)+(3*float(a))-2
- fb = pow(math.e,float(b))-pow(float(b),2)+(3*float(b))-2
- fc = pow(math.e,float(c))-pow(float(c),2)+(3*float(c))-2
- AB = abs(float(a)-float(b))
- #print(f'f(a): {fa}')
- #print(f'f(b): {fb}')
- #print(f'C: {c}')
- #print('f(c): {:f}'.format(truncate(float(fc))))
- #print(f'f(c): {truncate(float(fc))}')
- #print(f'|A-B|<Error: {AB}')
- f = ''
- if AB < error:
- f = 'YES'
- break
- else:
- f = 'NO'
- t.add_row([n, a, b, fa, fb, c, fc, AB, f])
- b = fb
- if f=='YES':
- break
- print(t)
- def truncate(n):
- return int(n * 1000000000) / 1000000000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement