You could just reverse the string using:
ans = ans[::-1]
Pregunta
So im trying to create a simple program that will add two binary strings together, im almost done but the output it creates is reversed, how would i implement a way to reverse it in my code? I want to remove the "ob" at the start of the output as well.
repeat = True
while repeat==True:
num1 = input("what number would you like to add ")
if num1.isdigit():
a= int(num1)
elif not num1.isdigit():
continue
a = int(num1, 2)
num2 = input("what number would you like to add to it ")
if num2.isdigit():
b= int(num2)
elif not num2.isdigit():
continue
b = int(num2, 2)
ans = bin(a+b)[2:]
print("Your addition of numbers, in binary is " + ans)
choice=input("Would you like to start again, y/n")
if choice== "y":
repeat=True
else:
print("Its not like i wanted you here or anything baka")
repeat=False
Solución
You could just reverse the string using:
ans = ans[::-1]