Question

Write a program that receives a real number in decimal (base 10) and converts it into...

Write a program that receives a real number in decimal (base 10) and converts it into any base (e.g., 2, 8, 16, 60) You may not use libraries or built-in functions (e.g., Double.toHexString(...) in Java or ”{0:b}”.format(...)in Python)

please in python exampe 0.5 convert to 0.1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

OUTPUT :

CODE :

num = int(input('Enter a real number: '))
b = int(input('Enter the base: '))
ans = ''
n = num
#COnvert while n>0
while n>0:
#Find remainder
rem = n%b
#Append it to ans
ans = '('+str(rem)+')'+ans
#Reduce number by b
n = n//b
print(num,'in base',b,' is',ans)

Add a comment
Know the answer?
Add Answer to:
Write a program that receives a real number in decimal (base 10) and converts it into...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT