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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!