Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def void(var):
- if var:
- input("ENTER to cancel")
- print("\n"*1000)
- def decimal(base,num):
- lun=len(num)-1
- num1=num[::-1]
- dec=0
- for kkkkk in range(len(num1)):
- if num1[kkkkk]=="A" and int(base) >=10:
- log=10
- elif num1[kkkkk]=="B" and int(base) >=11:
- log=11
- elif num1[kkkkk]=="C" and int(base) >=12:
- log=12
- elif num1[kkkkk]=="D" and int(base) >=13:
- log=13
- elif num1[kkkkk]=="E" and int(base) >=14:
- log=14
- elif num1[kkkkk]=="F" and int(base) >=15:
- log=15
- elif num1[kkkkk]=="G" and int(base) >=16:
- log=16
- elif num1[kkkkk]=="H" and int(base) >=17:
- log=17
- elif num1[kkkkk]=="I" and int(base) >=18:
- log=18
- elif num1[kkkkk]=="J" and int(base) >=19:
- log=19
- elif num1[kkkkk]=="K" and int(base) >=20:
- log=20
- elif num1[kkkkk]=="L" and int(base) >=21:
- log=21
- elif num1[kkkkk]=="M" and int(base) >=22:
- log=22
- elif num1[kkkkk]=="N" and int(base) >=23:
- log=23
- elif num1[kkkkk]=="O" and int(base) >=24:
- log=24
- elif num1[kkkkk]=="P" and int(base) >=25:
- log=25
- elif num1[kkkkk]=="Q" and int(base) >=26:
- log=26
- elif num1[kkkkk]=="R" and int(base) >=27:
- log=27
- elif num1[kkkkk]=="S" and int(base) >=28:
- log=28
- elif num1[kkkkk]=="T" and int(base) >=29:
- log=29
- elif num1[kkkkk]=="U" and int(base) >=30:
- log=30
- elif num1[kkkkk]=="V" and int(base) >=31:
- log=31
- elif num1[kkkkk]=="W" and int(base) >=32:
- log=32
- elif num1[kkkkk]=="X" and int(base) >=33:
- log=33
- elif num1[kkkkk]=="Y" and int(base) >=34:
- log=34
- elif num1[kkkkk]=="Z" and int(base) >=35:
- log=35
- else:
- log=num1[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("Unable to use the number, change the basis or change number")
- void(True)
- base()
- dec=dec+int(log)*(int(base)**kkkkk)
- print("Decimal = "+str(dec))
- binary(dec)
- def binary(a):
- d=e=l=""
- c=int(a)
- while True:
- if c==0:
- break
- else:
- l=c%2
- c=c//2
- d=d+str(l)
- e=d[::-1]
- print("Binary = "+e)
- hexadecimal(e)
- def hexadecimal(e):
- import re
- num={"0000":"0","1000":"1","0100":"2","1100":"3","0010":"4","1010":"5","0110":"6","1110":"7",
- "0001":"8","1001":"9","0101":"A","1101":"B","0011":"C","1011":"D","0111":"E","1111":"F"}
- x=""
- o="000"
- oe=o+e
- oe=oe[::-1]
- f=re.findall("....",oe)
- for lll in range(len(f)):
- k=f[lll]
- x=x+num[k]
- x=x[::-1]
- print("Hexadecimal = "+x)
- octal(e)
- def octal(e):
- import re
- num={"000":"0","100":"1","010":"2","110":"3","001":"4","101":"5","011":"6","111":"7"}
- x=""
- o="00"
- he=o+e
- he=he[::-1]
- f=re.findall("...",he)
- for lll in range(len(f)):
- k=f[lll]
- x=x+num[k]
- x=x[::-1]
- print("Octal = "+x)
- void(True)
- def base():
- try:
- import string
- void(False)
- d=e=l=""
- a=input("Enter the number to be converted: ")
- b=input("Enter the base number: ")
- 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
- decimal(b,a)
- except ZeroDivisionError:
- print("Use valid characters.")
- void(True)
- while True:
- base()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement