Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys. Can u help me pls. I want to choose in what base to convert my decimal number from 2 to 9.

What I have tried:

Python
def binär(a):            #Base 2
    number=0
    interim result = 0
    remains = []
    number=int(input("Enter a Number"))
    while number != 0:
      remains.append(number % 2)
      number = number // 2
      remains.reverse()
    for bit in remains:
        print(bit,end="")
        binär(a)
def binär(b):            #Base 3
    number=0
    interim result = 0
    remains = []
    number=int(input("Enter a Number"))
    while number != 0:
      remains.append(number % 3)
      number = number // 3
      remains.reverse()
    for bit in remains:
        print(bit,end="")
        binär(b)
binär()
Posted
Updated 19-Jun-20 21:04pm

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
 
Share this answer
 
i am trying to choose between these two function. If i want my decimal number to convert to binary then choose function(a). If i want to convert to base 3 number then choose function(b). In my code binär(b) shouldnt be binary but base3.


base3(b) should be like this: 4567(10):3= 1522 (1)
1522 :3= 507 (1)
507 :3= 169 (0)
169 :3= 56 (1)
56 :3= 18 (2)
18 :3= 6 (0)
6 :3= 2 (0)
2 :3= 0 (2)

so i want to choose between these two functions(base3 and binary). I am trying to bind them with a return command.
 
Share this answer
 
Comments
Richard MacCutchan 20-Jun-20 4:18am    
You can do this with a single function. Just pass it the number to convert in decimal, and the base you wish to convert it to.
Patrice T 20-Jun-20 8:48am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
Maciej Los 22-Jun-20 4:45am    
This is not an answer. Please, delete it to avoid down-voting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900