#! /usr/bin/env python # -*- coding: UTF-8 -*- """ ResisPy!, calcola la resistenza dai colori in python creato da Frafra (www.frafra-eu.org francesco.it@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ __module_name__ = "ResisPy!" __module_version__ = "0.8" __module_description__ = "Calcolatore di resistenze" color=[ "nero", "marrone", "rosso", "arancione", "giallo", "verde", "blu", "viola", "grigio", "bianco" ] incertezza={"oro":5, "argento":10, "":20} def put(txt, t=0): for x in range(5): data=raw_input(txt).lower() if data=="": print "Colore non valido:", data elif data in color and not t: return color.index(data) elif data in incertezza.keys(): return incertezza[data] else: print "Colore non valido:", data else: print "Sei troppo stupido per usare questo programma. Ritorno \"nero\"." return 0 def calc(n1, n2, n3=0, n4="n.d."): res=(n1*10+n2)*10**n3 return res, n4 ans="Inserisci un colore: " n1, n2, n3, n4=[put(ans) for x in range(4)] print "Resistenza: %d ohm +- %d (incertezza percentuale)" % calc(n1, n2, n3, n4)