if "^" in fx:
list1 = fx.split("x^")
n = int(list1[0]) * int(list1[1])
m = int(list1[1]) - 1
if m == 1:return "".join(str(n) + "x")
else:return "".join(str(n) + "x^" + str(m))
elif "x" in fx:return fx[:-1]
else:return "0"
def solution(fx: str) -> str:
n = 1 if ('x' in fx and '^' not in fx) else 0 if 'x^' not in fx else None
f_list = fx.split('x') if n == 1 else fx.split('x^')
if n is None:
n = int(f_list[-1])
return str(int(f_list[0]) * n) + ('x' if n not in [0, 1] else '') + ('' if n in [1, 2, 0, None] else '^' + str(n - 1))
assert solution("3x^2") == "6x"
assert solution("6x^-2") == "-12x^-3"
assert solution("5x") == "5"
assert solution("42") == "0"
def solution4(fx: str) → str:
if “x” not in fx:
return “0”
else:
if “^” not in fx:
num = fx.split(“x”)
return num[0]
else:
num = fx.split(“x^”)
a = int(num[0])
b = int(num[1])
if b == 2:
return str(ab) + “x”
else:
return str(ab) + “x^” + str(b-1)
def solution(f: str) -> str:
if "^" not in f:
if "x" not in f:
return "0"
return f[0]
if "^" in f:
a, b = f.split("^")
if b == '2':
return str(int(a[:-1]) * int(b)) + "x"
return str(int(a[:-1]) * int(b)) + "x^" + str(int(b) - 1)
def solution(fx: str) -> str:
if "x" in fx:
lis = fx.split("x")
if "^" not in fx:
return lis[0]
else:
a = int(lis[0])
b = int(lis[1][1:])
if b == 2:
return f"{a * b}x"
return f"{a * b}x^{b - 1}"
else:
return "0"