current_price = int(input())last_months_price = int(input())print("This house is $" + str(current_price), '.', "The change is $" + str(current_price - last_months_price) + " since last month.")print("The estimated monthly mortgage is ${:.2f}".format((current_price * 0.051) / 12), '.')这会产生:This house is $200000 . The change is $-10000 since last month.The estimated monthly mortgage is $850.00 ."$200000"我不确定如何删除and之后的空白"$850.00"。我不完全理解这个strip()命令,但从我读到的内容来看,它对这个问题没有帮助。
3 回答

ABOUTYOU
TA贡献1812条经验 获得超5个赞
你可以给 print 一个额外的参数:sep
,像这样:
print("This house is $" + str(current_price), '.', "The change is $" + str(current_price - last_months_price) + " since last month.", sep='')
因为默认是逗号后的空格。

手掌心
TA贡献1942条经验 获得超3个赞
也许尝试 f-string 注入
print(f"This house is ${current_price}. The change is ${current_price - last_months_price} since last month.")
f-string(格式化字符串)提供了一种使用最少语法将表达式嵌入字符串文字的方法。这是一种连接字符串的简化方法,无需显式调用str
除字符串以外的格式化数据类型。
您也可以传递sep=''
给print
,但这需要您将其他字符串与格式正确的空格连接起来。

斯蒂芬大帝
TA贡献1827条经验 获得超8个赞
print("This house is $" + str(current_price), '.',' ' "The change is $" +
str(current_price - last_months_price) + " since last month.", sep='')
print("The estimated monthly mortgage is ${:.2f}"'.'.format((current_price * 0.051) / 12))
添加回答
举报
0/150
提交
取消