我正在学习python,正在尝试制作另一个计算器。当我尝试运行它时,前几个命令起作用,但是当我到达第6行时,它说:TypeError:只能将str(而不是“ int”)连接到str代码在这里
if user_input==' squares':
first_number=input(str(inp_words))
second_number=input(str(sec_inp_words))
f_num=str(first_number)
s_num=str(second_number)
answer=int(first_number)**int(second_number)
print('the answer to '+str(f_num)+'to the power of'+str(s_num)+'is'+answer)
print(str(words))
sys.exit()
这应该做:
print(f'the answer to {f_num} to the power of {s_num} is {answer}.')