How to use 'how to find percentage in python' in Python

Every line of 'how to find percentage in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
172def get_percentage(i, n):
173 if n == 0:
174 return '0 %'
175 else:
176 v = 100 * (1.0 * i / n)
177 return '%.1f %%' % v
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

93def percent(numerator, denominator):
94 """
95 :param numerator: float
96 Numerator of fraction
97 :param denominator: float
98 Denominator of fraction
99 :return: str
100 Fraction as percentage
101 """
102
103 if denominator == 0:
104 out = "0"
105 else:
106 out = str(int(numerator / float(denominator) * 100))
107
108 return out + "%"

Related snippets