Question: Hi i need help making a function that implements a negate function into my convert to decimal function in python input :++- output: should be
Hi i need help making a function that implements a negate function into my convert to decimal function in python
input :"++-" output: should be 11
negate(n)
Given a string n representing a balanced ternary number,returns the string representing -n. Hint: you should use this in convert_to_balanced_ternary(n)! If n is invalid, return the empty string
Here is my code below
def convert_to_balanced_ternary(n): conversion = ""
while n>0: conversion = str(n%3) + conversion n = int(n/3) return conversion
print(convert_to_balanced_ternary("++-"))
my code might be wrong
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
