Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use = True
- import os
- import time
- from sys import platform
- def bannerwin():
- print(" ")
- print(".oPYo. o o ")
- print("8 8 8 8 ")
- print("8 .oPYo. odYo. o o 8 odYo. o8P ")
- print("8 8 8 8' `8 Y. .P 8 8' `8 8 ")
- print("8 8 8 8 8 8 `b..d' 8 8 8 8 ")
- print("`YooP' `YooP' 8 8 `YP' 8 8 8 8 ")
- print(":.....::.....:..::..::...::....::..::..:")
- print("::::::::::::::::::::::::::::::::::::::::")
- print("::::::::::::::::::::::::::::::::::::::::")
- print("ConvInt, found on github.com/georgeomnet\n")
- def clearcheck():
- if "win" in platform.lower() or platform == "darwin":
- print("========================================================\n")
- else:
- os.system("clear")
- def errormessagelater():
- print("Sorry! That wasn't a valid answer.")
- time.sleep(1)
- use = True
- clearcheck()
- def runden():
- usernum = input("Enter your denary number: ")
- try:
- print("Here are the stats for %s:" % usernum)
- print("Its hexadecimal is:",format(int(usernum), '02X'))
- print("Its binary is:","{0:b}".format(int(usernum)))
- print("Its octal decimal is:",oct(int(usernum)))
- except:
- print("Sorry, that number is not valid.")
- runden()
- def runbin():
- usernum = input("Enter your binary number: ")
- try:
- print("Here are the stats for %s:" % usernum)
- print("Its denary is:",int(usernum, 2))
- print("Its hexadecimal is:",format(int(usernum), '02X'))
- print("Its octal decimal is:",oct(int(usernum)))
- except:
- print("Sorry, that number is not valid.")
- runbin()
- def runhex():
- usernum = input("Enter your hexadecimal number: ")
- try:
- print("Here are the stats for %s:" % usernum)
- print("Its denary is:",int(usernum, 16))
- print("Its binary is:",bin(int(usernum, 16))[2:])
- print("Its octal decimal is:",oct(int(usernum, 16)))
- except:
- print("Sorry, that is not a valid hex.")
- runhex()
- def runoct():
- usernum = input("Enter your octal decimal: ")
- try:
- print("Here are the stats for %s" % usernum)
- print("Its denary is:",int(usernum, 8))
- print("Its binary is:",bin(int(usernum, 8))[2:])
- print("Its hexadecimal is:",format(int(int(usernum, 8)), '02x'))
- except:
- print("Sorry, that oct is not valid.")
- runoct()
- def prog():
- typeofchar = input("Is your number Denary (d), Binary (b), Hexadecimal (h) or Octal decimal (o)?\n")
- typeofchar = typeofchar.lower()
- typeofchar = typeofchar[0]
- if typeofchar == "d":
- runden()
- elif typeofchar == "b":
- runbin()
- elif typeofchar == "h":
- runhex()
- elif typeofchar == "o":
- runoct()
- else:
- print("Sorry! Your number is not valid.")
- while use == True:
- bannerwin()
- prog()
- ask = input("Would you like to go again? y/n\n")
- try:
- ask = ask[0]
- ask = ask.lower()
- except:
- errormessagelater()
- if ask == "n":
- use = False
- elif ask == "y":
- use = True
- clearcheck()
- else:
- errormessagelater()
Add Comment
Please, Sign In to add comment