Advertisement
Dar954826

Convertitore Basi Nuovo[ITA].py.py

Jan 16th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.34 KB | None | 0 0
  1. def void(var):
  2.  if var:
  3.   input("INVIO per cancellare")
  4.  print("\n"*1000)
  5. def decimale(base,numero):
  6.  try:
  7.   c=input("Inserire in quali basi convertire:[Separare con uno spazio] ")
  8.   if c=="":
  9.    c="16 8 2 10"
  10.   c=c.split(" ")
  11.   for may in c:
  12.    c[c.index(may)]=int(may)
  13.   c.sort()
  14.   if c[len(c)-1]>36 or c[0]<2:
  15.    6/0
  16.  except ValueError:
  17.   print("Valore non valido.")
  18.   void(True)
  19.   base()
  20.  except ZeroDivisionError:
  21.   print("Inserire numeri compresi tra 2 e 36")
  22.   void(True)
  23.   base()
  24.  conver={}
  25.  co=do=""
  26.  con=1
  27.  lun=len(numero)-1
  28.  numero1=numero[::-1]
  29.  dec=0
  30.  for kkkkk in range(len(numero1)):
  31.   if numero1[kkkkk]=="A" and int(base) >=10:
  32.    log=10
  33.   elif numero1[kkkkk]=="B" and int(base) >=11:
  34.    log=11
  35.   elif numero1[kkkkk]=="C" and int(base) >=12:
  36.    log=12
  37.   elif numero1[kkkkk]=="D" and int(base) >=13:
  38.    log=13
  39.   elif numero1[kkkkk]=="E" and int(base) >=14:
  40.    log=14
  41.   elif numero1[kkkkk]=="F" and int(base) >=15:
  42.    log=15
  43.   elif numero1[kkkkk]=="G" and int(base) >=16:
  44.    log=16
  45.   elif numero1[kkkkk]=="H" and int(base) >=17:
  46.    log=17
  47.   elif numero1[kkkkk]=="I" and int(base) >=18:
  48.    log=18
  49.   elif numero1[kkkkk]=="J" and int(base) >=19:
  50.    log=19
  51.   elif numero1[kkkkk]=="K" and int(base) >=20:
  52.    log=20
  53.   elif numero1[kkkkk]=="L" and int(base) >=21:
  54.    log=21
  55.   elif numero1[kkkkk]=="M" and int(base) >=22:
  56.    log=22
  57.   elif numero1[kkkkk]=="N" and int(base) >=23:
  58.    log=23
  59.   elif numero1[kkkkk]=="O" and int(base) >=24:
  60.    log=24
  61.   elif numero1[kkkkk]=="P" and int(base) >=25:
  62.    log=25
  63.   elif numero1[kkkkk]=="Q" and int(base) >=26:
  64.    log=26
  65.   elif numero1[kkkkk]=="R" and int(base) >=27:
  66.    log=27
  67.   elif numero1[kkkkk]=="S" and int(base) >=28:
  68.    log=28
  69.   elif numero1[kkkkk]=="T" and int(base) >=29:
  70.    log=29
  71.   elif numero1[kkkkk]=="U" and int(base) >=30:
  72.    log=30
  73.   elif numero1[kkkkk]=="V" and int(base) >=31:
  74.    log=31
  75.   elif numero1[kkkkk]=="W" and int(base) >=32:
  76.    log=32
  77.   elif numero1[kkkkk]=="X" and int(base) >=33:
  78.    log=33
  79.   elif numero1[kkkkk]=="Y" and int(base) >=34:
  80.    log=34
  81.   elif numero1[kkkkk]=="Z" and int(base) >=35:
  82.    log=35
  83.   else:
  84.    log=numero1[kkkkk]
  85.   if str(log).count("0")==0 and str(log).count("1")==0 and str(log).count("2")==0 and str(log).count("3")==0 and str(log).count("4")==0 and str(log).count("5")==0 and str(log).count("6")==0 and  str(log).count("7")==0 and str(log).count("8")==0 and str(log).count("9")==0:
  86.    try:
  87.     6/0
  88.    except ZeroDivisionError:
  89.     print("Impossibile utilizzare il numero, cambiare base o cambiare numero")
  90.     void(True)
  91.     base()
  92.   dec=dec+int(log)*(int(base)**kkkkk)
  93.  while True:
  94.   co=dec
  95.   if con==36:
  96.    break
  97.   con=con+1
  98.   while co!=0:
  99.    bo=co%con
  100.    co=co//con
  101.    if bo==10:
  102.     log="A"
  103.    elif bo==11:
  104.     log="B"
  105.    elif bo==12:
  106.     log="C"
  107.    elif bo==13:
  108.     log="D"
  109.    elif bo==14:
  110.     log="E"
  111.    elif bo==15:
  112.     log="F"
  113.    elif bo==16:
  114.     log="G"
  115.    elif bo==17:
  116.     log="H"
  117.    elif bo==18:
  118.     log="I"
  119.    elif bo==19:
  120.     log="J"
  121.    elif bo==20:
  122.     log="K"
  123.    elif bo==21:
  124.     log="L"
  125.    elif bo==22:
  126.     log="M"
  127.    elif bo==23:
  128.     log="N"
  129.    elif bo==24:
  130.     log="O"
  131.    elif bo==25:
  132.     log="P"
  133.    elif bo==26:
  134.     log="Q"
  135.    elif bo==27:
  136.     log="R"
  137.    elif bo==28:
  138.     log="S"
  139.    elif bo==29:
  140.     log="T"
  141.    elif bo==30:
  142.     log="U"
  143.    elif bo==31:
  144.     log="V"
  145.    elif bo==32:
  146.     log="W"
  147.    elif bo==33:
  148.     log="X"
  149.    elif bo==34:
  150.     log="Y"
  151.    elif bo==35:
  152.     log="Z"
  153.    else:
  154.     log=str(bo)
  155.    do=do+log
  156.   conver[str(con)]=do[::-1]
  157.   do=""
  158.  for k in c:
  159.   if k==2:
  160.    lol="binaria"
  161.   elif k==16:
  162.    lol="esadecimale"
  163.   elif k==8:
  164.    lol="ottale"
  165.   elif k==10:
  166.    lol="decimale"
  167.   else:
  168.    lol=str(k)
  169.   print("Base "+lol+" : "+conver[str(k)])
  170.  print("Conversioni completate")
  171.  void(True)
  172. def base():
  173.  mmm=0
  174.  try:
  175.   import string
  176.   if mmm!=0:
  177.    bol=False
  178.   else:
  179.    bol=True
  180.   if bol:
  181.    void(False)
  182.   mmm+1
  183.   d=e=l=""
  184.   a=input("Inserire il numero da convertire: ")
  185.   b=input("Inserire base numero: ")
  186.   a=a.upper()
  187.   for kjkj in string.ascii_letters:
  188.    if b.count(kjkj)!=0 or b=="" or a=="":
  189.     6/0
  190.   for kjkjk in string.punctuation:
  191.    if a.count(kjkjk)!=0 :
  192.     6/0
  193.    if b.count(kjkjk)!=0:
  194.     6/0
  195.   decimale(b,a)
  196.  except ZeroDivisionError:
  197.   print("Utilizzare caratteri validi.")
  198.   void(True)
  199. while True:
  200.  base()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement