不变变量

问题描述 投票:-1回答:1

我正在学习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()
python variables python-3.8
1个回答
0
投票

这应该做:

print(f'the answer to {f_num} to the power of {s_num} is {answer}.')
© www.soinside.com 2019 - 2024. All rights reserved.