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), '.')這會產(chǎn)生:This house is $200000 . The change is $-10000 since last month.The estimated monthly mortgage is $850.00 ."$200000"我不確定如何刪除and之后的空白"$850.00"。我不完全理解這個strip()命令,但從我讀到的內(nèi)容來看,它對這個問題沒有幫助。
3 回答

ABOUTYOU
TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊
你可以給 print 一個額外的參數(shù):sep
,像這樣:
print("This house is $" + str(current_price), '.', "The change is $" + str(current_price - last_months_price) + " since last month.", sep='')
因為默認(rèn)是逗號后的空格。

手掌心
TA貢獻(xiàn)1942條經(jīng)驗 獲得超3個贊
也許嘗試 f-string 注入
print(f"This?house?is?${current_price}.?The?change?is?${current_price?-?last_months_price}?since?last?month.")
f-string(格式化字符串)提供了一種使用最少語法將表達(dá)式嵌入字符串文字的方法。這是一種連接字符串的簡化方法,無需顯式調(diào)用str
除字符串以外的格式化數(shù)據(jù)類型。
您也可以傳遞sep=''
給print
,但這需要您將其他字符串與格式正確的空格連接起來。

斯蒂芬大帝
TA貢獻(xiàn)1827條經(jīng)驗 獲得超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
提交
取消