Click here to Skip to main content
15,851,319 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Sample input:

Sample output:

What I have tried:

a = int(input())
b = int(input())
c = int(input())
len_a = len(a)
len_b = len(b)
s = ''
diff = abs((len_a-len_b))
for i in range(1,diff+1):
if len_a<len_b:
   a = s+a
   b = s+b
Updated 7-Feb-22 6:54am

Once you have the integer values you can simply add them together to get the total. This holds true for any number.

The key to your question is how to display them in the correct format. You need to use the base number to calculate each digit of the string. This is done by taking the remainder of the number divided by the base repeatedly, until you have used up all the number. You then need to order those numbers correctly before displaying them. Taking your numbers above:
123 + 13 = 136
136 / 4 = 34 remainder 0
34 / 4  =  8 remainder 2
8 / 4   =  2 remainder 0
2 / 4   =  0 remainder 2
So the final display is: 2020 base 4

Oops I misread the question. In order to get the values in a specific base to start with, you need to convert each successive digit. So do not input them directly as int types, but read them as a string. Start with a sum variable set to zero. You then take each character and convert it to an int. Then multiply the sum by the base and add the integer value to it. Repeat that for each digit in the string. You can then add the two numbers together and display them as described above.
Share this answer
This is the same question you asked yesterday: Add two numbers given in base n format in python.[^]
And since I told you exactly what to do then and you've ignored it, there is no point at all in asking it again.

If I was you, I'd spend the five or ten minutes it would take you to write the code yourself instead of trying to get other people to do it for you: your homework "hand in" deadline must be getting close ...
Share this answer
Richard MacCutchan 7-Feb-22 10:30am    
I missed that. Although to be fair he/she/it/them has clarified the issue slightly.

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