How to calculate percentage from two numbers in Python

1 Answer

0 votes
def percentage(part, whole):
   return 100 * float(part)/float(whole)

print(percentage(16, 32), '%', sep='')
print(percentage(32, 16), '%', sep='')
print(percentage(15, 32), '%', sep='')

 
'''
run:
 
50.00%
200.00%
46.88%
  
'''

 



answered Jul 29, 2019 by avibootz
...