Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def void(var):
- if var:
- input("INVIO per cancellare")
- print("\n"*1000)
- def decimale(base,numero):
- try:
- c=input("Inserire in quali basi convertire:[Separare con uno spazio] ")
- if c=="":
- c="16 8 2 10"
- c=c.split(" ")
- for may in c:
- c[c.index(may)]=int(may)
- c.sort()
- if c[len(c)-1]>36 or c[0]<2:
- 6/0
- except ValueError:
- print("Valore non valido.")
- void(True)
- base()
- except ZeroDivisionError:
- print("Inserire numeri compresi tra 2 e 36")
- void(True)
- base()
- conver={}
- co=do=""
- con=1
- lun=len(numero)-1
- numero1=numero[::-1]
- dec=0
- for kkkkk in range(len(numero1)):
- if numero1[kkkkk]=="A" and int(base) >=10:
- log=10
- elif numero1[kkkkk]=="B" and int(base) >=11:
- log=11
- elif numero1[kkkkk]=="C" and int(base) >=12:
- log=12
- elif numero1[kkkkk]=="D" and int(base) >=13:
- log=13
- elif numero1[kkkkk]=="E" and int(base) >=14:
- log=14
- elif numero1[kkkkk]=="F" and int(base) >=15:
- log=15
- elif numero1[kkkkk]=="G" and int(base) >=16:
- log=16
- elif numero1[kkkkk]=="H" and int(base) >=17:
- log=17
- elif numero1[kkkkk]=="I" and int(base) >=18:
- log=18
- elif numero1[kkkkk]=="J" and int(base) >=19:
- log=19
- elif numero1[kkkkk]=="K" and int(base) >=20:
- log=20
- elif numero1[kkkkk]=="L" and int(base) >=21:
- log=21
- elif numero1[kkkkk]=="M" and int(base) >=22:
- log=22
- elif numero1[kkkkk]=="N" and int(base) >=23:
- log=23
- elif numero1[kkkkk]=="O" and int(base) >=24:
- log=24
- elif numero1[kkkkk]=="P" and int(base) >=25:
- log=25
- elif numero1[kkkkk]=="Q" and int(base) >=26:
- log=26
- elif numero1[kkkkk]=="R" and int(base) >=27:
- log=27
- elif numero1[kkkkk]=="S" and int(base) >=28:
- log=28
- elif numero1[kkkkk]=="T" and int(base) >=29:
- log=29
- elif numero1[kkkkk]=="U" and int(base) >=30:
- log=30
- elif numero1[kkkkk]=="V" and int(base) >=31:
- log=31
- elif numero1[kkkkk]=="W" and int(base) >=32:
- log=32
- elif numero1[kkkkk]=="X" and int(base) >=33:
- log=33
- elif numero1[kkkkk]=="Y" and int(base) >=34:
- log=34
- elif numero1[kkkkk]=="Z" and int(base) >=35:
- log=35
- else:
- log=numero1[kkkkk]
- 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:
- try:
- 6/0
- except ZeroDivisionError:
- print("Impossibile utilizzare il numero, cambiare base o cambiare numero")
- void(True)
- base()
- dec=dec+int(log)*(int(base)**kkkkk)
- while True:
- co=dec
- if con==36:
- break
- con=con+1
- while co!=0:
- bo=co%con
- co=co//con
- if bo==10:
- log="A"
- elif bo==11:
- log="B"
- elif bo==12:
- log="C"
- elif bo==13:
- log="D"
- elif bo==14:
- log="E"
- elif bo==15:
- log="F"
- elif bo==16:
- log="G"
- elif bo==17:
- log="H"
- elif bo==18:
- log="I"
- elif bo==19:
- log="J"
- elif bo==20:
- log="K"
- elif bo==21:
- log="L"
- elif bo==22:
- log="M"
- elif bo==23:
- log="N"
- elif bo==24:
- log="O"
- elif bo==25:
- log="P"
- elif bo==26:
- log="Q"
- elif bo==27:
- log="R"
- elif bo==28:
- log="S"
- elif bo==29:
- log="T"
- elif bo==30:
- log="U"
- elif bo==31:
- log="V"
- elif bo==32:
- log="W"
- elif bo==33:
- log="X"
- elif bo==34:
- log="Y"
- elif bo==35:
- log="Z"
- else:
- log=str(bo)
- do=do+log
- conver[str(con)]=do[::-1]
- do=""
- for k in c:
- if k==2:
- lol="binaria"
- elif k==16:
- lol="esadecimale"
- elif k==8:
- lol="ottale"
- elif k==10:
- lol="decimale"
- else:
- lol=str(k)
- print("Base "+lol+" : "+conver[str(k)])
- print("Conversioni completate")
- void(True)
- def base():
- mmm=0
- try:
- import string
- if mmm!=0:
- bol=False
- else:
- bol=True
- if bol:
- void(False)
- mmm+1
- d=e=l=""
- a=input("Inserire il numero da convertire: ")
- b=input("Inserire base numero: ")
- a=a.upper()
- for kjkj in string.ascii_letters:
- if b.count(kjkj)!=0 or b=="" or a=="":
- 6/0
- for kjkjk in string.punctuation:
- if a.count(kjkjk)!=0 :
- 6/0
- if b.count(kjkjk)!=0:
- 6/0
- decimale(b,a)
- except ZeroDivisionError:
- print("Utilizzare caratteri validi.")
- void(True)
- while True:
- base()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement