Allegato "perc_minus.py"
Scarica 1 #!/usr/bin/env python3
2
3 # This script calculates the percent reduction (things like 124,5 - 15%).
4 # It takes in consideration floats entered with commas.
5 # Results will be displayed as strings in the form e.g. 124,5 - 15% = 105,825
6
7 from sys import argv
8 script, total, part = argv
9
10 ## If float ends with .00 it will be converted to integer
11 def change_to_integer(n):
12 if n - int(n) == 0.00:
13 n = int(n)
14 return n
15
16 ## Commas replaced with dots โ conversion to float
17 total = float(total.replace(",", "."))
18 part = float(part.replace(",", "."))
19
20 final_result = total - (total * part / 100)
21
22 ## Conversions to integers if floats ends with .00 โ conversion to strings
23 ## โ replacement of dots with commas
24 total = str(change_to_integer(total)).replace(".", ",")
25 part = str(change_to_integer(part)).replace(".", ",")
26 final_result = str(change_to_integer(final_result)).replace(".", ",")
27
28 print("\n{} - {}% = {}\n".format(total, part, final_result))
Allegati
Per riferirsi agli allegati di una pagina, usare attachment:NOME_FILE, come mostrato qui sotto nell'elenco degli allegati. NON usare l'URL che si trova in corrispondenza del collegamento [scarica], potrebbe cambiare in futuro.Non รจ consentito inserire allegati su questa pagina.