convert to percentage python code example

Example 1: percentage change python

# How to see percent change using python 
# Using python==3.8.6 

example_nums = [8, 16, 4, -6, 7, 84] 

def percent_change(start_point, end_point):
  # This is going to be a little long but bare with me here
  return ((float(end_point) - start_point) / abs(start_point)) * 100.00 

for numbers in example_nums:
  percentage = percent_change(example_nums[0], numbers) 
  print(str(numbers) + ' -- ' + str(percentage))
 
# The output should look like:
#8 -- 0.0 
#16 -- 100.0 
#4 -- -50.0 
#-6 -- -175.0
#7 -- -12.5 
#84 -- 950.0

Example 2: python convert to percentage

your_value = 1/3.0
print('{:.1%}'.format(your_value)) # Change the "1" to however many decimal places you need
# Result:
# '33.3%'