Advertisement
Guest User

Untitled

a guest
Sep 8th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #By Rayner Da Cruz
  2. import time
  3. n=0
  4. while n!=1:
  5. error=True
  6. error1=True
  7. error2=True
  8. print"\n"
  9. print" *************************************"
  10. print" *!Welcome to RBDC BinAdd Calculator!*"
  11. print" *+++++++++++++1-Bin_Add+++++++++++++*"
  12. print" *+++++++++++++++2-Exit++++++++++++++*"
  13. print" *************************************"
  14. print" Build 1.9.5 FINAL\n"
  15.  
  16. while error:
  17. try:
  18. choice=input("Select a Option: ")
  19. print "\n"
  20. if choice >=3:
  21. print"Please enter a number between 1-2."
  22. error=False
  23. except NameError:
  24. print"Not a number. Please try again."
  25. time.sleep(1)
  26. except SyntaxError:
  27. print"Not a number. Please try again."
  28. time.sleep(1)
  29.  
  30. if choice ==1:
  31. print"***You have selected Bin_Add.***\n"
  32. while error1:
  33. try:
  34. bin2dec = raw_input("Please enter 1st binary number: ")
  35. bin2dec2 = raw_input("Please enter 2nd binary number: ")
  36. error1=False
  37. except NameError:
  38. print"Enter a Binary number. Please try again.\n"
  39. time.sleep(0.5)
  40. except SyntaxError:
  41. print"Enter a Binary number. Please try again.\n"
  42. time.sleep(0.5)
  43.  
  44. decimal=0
  45. for i in bin2dec:
  46. decimal= decimal * 2 + int(i)
  47.  
  48. decimal2=0
  49. for i in bin2dec2:
  50. decimal2= decimal2 * 2 + int(i)
  51.  
  52. a=decimal+decimal2 #adds the 2 variables and converts to binary
  53. c=decimal+decimal2
  54.  
  55. b = ''
  56. while a>0:
  57. b = str(a % 2) + b
  58. a >>= 1
  59. print "\n",c,"=",str(b),"<<This is your answer!" #prints output dec = number in binary with dec equivalent.
  60.  
  61. if choice==2:
  62. while error2:
  63. try:
  64. endex=input("Do you want to Exit? \nInput (1)y or (2)n: ")
  65. if endex== 0 or endex >=3:
  66. print"Try again"
  67. if endex==2:
  68. print "You have chosen to run this programme again...\n"
  69. if endex==1:
  70. print "\nThank you for using RBDC Bin2Dec Converter \nGoodbye"
  71. time.sleep(1)
  72. break
  73. error2=False
  74.  
  75. except NameError:
  76. print"\nError. Enter 1 or 2."
  77. except SyntaxError:
  78. print"\nError. Enter 1 or 2."
  79.  
  80. #By Rayner Da Cruz
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement