1def percentage(part, whole):
2 return 100 * float(part)/float(whole)
3
4print(percentage(5, 7))
5# If you want to limit the number of decimal to 2, change the number in {:.2f} as you wish;
6print('{:.2f}'.format(percentage(5, 7)))
1your_value = 1/3.0
2print('{:.1%}'.format(your_value)) # Change the "1" to however many decimal places you need
3# Result:
4# '33.3%'