how to get percentage in python
def percentage(part, whole):
return 100 * float(part)/float(whole)
print(percentage(5, 7))
# If you want to limit the number of decimal to 2, change the number in {:.2f} as you wish;
print('{:.2f}'.format(percentage(5, 7)))
3.8
5
your_value = 1/3.0
print('{:.1%}'.format(your_value)) # Change the "1" to however many decimal places you need
# Result:
# '33.3%'
Thank you!
5
0
4.8
5
quotient = 1000000 / 10
Thank you!
5
0
Are there any code examples left?
New code examples in category Python