percentage change python

Solutions on MaxInterview for percentage change python by the best coders in the world

showing results for - "percentage change python"
Jonas
19 Jan 2016
1# How to see percent change using python 
2# Using python==3.8.6 
3
4example_nums = [8, 16, 4, -6, 7, 84] 
5
6def percent_change(start_point, end_point):
7  # This is going to be a little long but bare with me here
8  return ((float(end_point) - start_point) / abs(start_point)) * 100.00 
9
10for numbers in example_nums:
11  percentage = percent_change(example_nums[0], numbers) 
12  print(str(numbers) + ' -- ' + str(percentage))
13 
14# The output should look like:
15#8 -- 0.0 
16#16 -- 100.0 
17#4 -- -50.0 
18#-6 -- -175.0
19#7 -- -12.5 
20#84 -- 950.0
21