Guest User

Untitled

a guest
Feb 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. use = True
  2. import os
  3. import time
  4. from sys import platform
  5.  
  6. def bannerwin():
  7. print(" ")
  8. print(".oPYo. o o ")
  9. print("8 8 8 8 ")
  10. print("8 .oPYo. odYo. o o 8 odYo. o8P ")
  11. print("8 8 8 8' `8 Y. .P 8 8' `8 8 ")
  12. print("8 8 8 8 8 8 `b..d' 8 8 8 8 ")
  13. print("`YooP' `YooP' 8 8 `YP' 8 8 8 8 ")
  14. print(":.....::.....:..::..::...::....::..::..:")
  15. print("::::::::::::::::::::::::::::::::::::::::")
  16. print("::::::::::::::::::::::::::::::::::::::::")
  17. print("ConvInt, found on github.com/georgeomnet\n")
  18.  
  19. def clearcheck():
  20. if "win" in platform.lower() or platform == "darwin":
  21. print("========================================================\n")
  22. else:
  23. os.system("clear")
  24.  
  25. def errormessagelater():
  26. print("Sorry! That wasn't a valid answer.")
  27. time.sleep(1)
  28. use = True
  29. clearcheck()
  30.  
  31. def runden():
  32. usernum = input("Enter your denary number: ")
  33. try:
  34. print("Here are the stats for %s:" % usernum)
  35. print("Its hexadecimal is:",format(int(usernum), '02X'))
  36. print("Its binary is:","{0:b}".format(int(usernum)))
  37. print("Its octal decimal is:",oct(int(usernum)))
  38. except:
  39. print("Sorry, that number is not valid.")
  40. runden()
  41.  
  42. def runbin():
  43. usernum = input("Enter your binary number: ")
  44. try:
  45. print("Here are the stats for %s:" % usernum)
  46. print("Its denary is:",int(usernum, 2))
  47. print("Its hexadecimal is:",format(int(usernum), '02X'))
  48. print("Its octal decimal is:",oct(int(usernum)))
  49. except:
  50. print("Sorry, that number is not valid.")
  51. runbin()
  52.  
  53. def runhex():
  54. usernum = input("Enter your hexadecimal number: ")
  55. try:
  56. print("Here are the stats for %s:" % usernum)
  57. print("Its denary is:",int(usernum, 16))
  58. print("Its binary is:",bin(int(usernum, 16))[2:])
  59. print("Its octal decimal is:",oct(int(usernum, 16)))
  60. except:
  61. print("Sorry, that is not a valid hex.")
  62. runhex()
  63.  
  64.  
  65. def runoct():
  66. usernum = input("Enter your octal decimal: ")
  67. try:
  68. print("Here are the stats for %s" % usernum)
  69. print("Its denary is:",int(usernum, 8))
  70. print("Its binary is:",bin(int(usernum, 8))[2:])
  71. print("Its hexadecimal is:",format(int(int(usernum, 8)), '02x'))
  72. except:
  73. print("Sorry, that oct is not valid.")
  74. runoct()
  75.  
  76. def prog():
  77. typeofchar = input("Is your number Denary (d), Binary (b), Hexadecimal (h) or Octal decimal (o)?\n")
  78. typeofchar = typeofchar.lower()
  79. typeofchar = typeofchar[0]
  80. if typeofchar == "d":
  81. runden()
  82. elif typeofchar == "b":
  83. runbin()
  84. elif typeofchar == "h":
  85. runhex()
  86. elif typeofchar == "o":
  87. runoct()
  88. else:
  89. print("Sorry! Your number is not valid.")
  90.  
  91. while use == True:
  92. bannerwin()
  93. prog()
  94. ask = input("Would you like to go again? y/n\n")
  95. try:
  96. ask = ask[0]
  97. ask = ask.lower()
  98. except:
  99. errormessagelater()
  100. if ask == "n":
  101. use = False
  102. elif ask == "y":
  103. use = True
  104. clearcheck()
  105. else:
  106. errormessagelater()
Add Comment
Please, Sign In to add comment