SHARE
TWEET

Decimal to base converter

a guest Dec 11th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def convert_to_base(number, base):
  2.     remainder_list = []
  3.     while number != 0:
  4.         remainder_list.append(str(number % base))
  5.         number = number // base
  6.     remainder_list.reverse()
  7.     return "".join(remainder_list)
  8.  
  9. def ask_to_convert(repeat = ""):
  10.     convert_yn = input(f"Do you want to convert a base 10 number{repeat}?(y/n): ")
  11.     return convert_yn
  12.  
  13. def main():
  14.     print("This program converts a base 10 number to a number of any base \n")
  15.     convert_yn = ask_to_convert()
  16.     while convert_yn == "y":
  17.         user_number = int(input("Enter a base 10 number to convert: "))
  18.         user_base = int(input("Enter a base: "))
  19.         print(f"the base {user_base} equivalent to decimal numeral {user_number} is: ", convert_to_base(user_number, user_base), "\n")
  20.         convert_yn = ask_to_convert(" again")
  21.         if convret_yn == "n":
  22.             print("Goodbye")
  23.  
  24. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top