Wiki Ubuntu-it

Indice
Partecipa
FAQ
Wiki Blog
------------------
Ubuntu-it.org
Forum
Chiedi
Chat
Cerca
Planet
  • Pagina non alterabile
  • Informazioni
  • Allegati
  • attachment:perc_plus.py di UbuntuPhone/RisoluzioneProblemi/PercentualeCalcolatrice

Allegato "perc_plus.py"

Scarica

   1 #!/usr/bin/env python3
   2 
   3 # This script calculates the percent increase (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.
  • [scarica | mostra] (08/11/2016 01.49.50, 0.9 KB) [[attachment:perc.py]]
  • [scarica | mostra] (08/11/2016 01.51.21, 0.9 KB) [[attachment:perc_minus.py]]
  • [scarica | mostra] (08/11/2016 01.51.43, 0.9 KB) [[attachment:perc_plus.py]]
 All files | Selected Files: delete move to page copy to page

Non รจ consentito inserire allegati su questa pagina.