我在介紹編程類中,並且已丟失。我們有幾個實驗室需要知識,我們沒有教過,但我已經設法找出我需要谷歌(因爲沒有人迴應類留言板),但這個讓我非常沮喪。我會包括這裏引擎收錄鏈接:https://pastebin.com/6JBD6NNA在輸出中使用逗號
`principal = input()
print('Enter the Principal Value of your investment: $', float(principal))
time = input()
print('\nEnter the Time(in years) you plan to save your investment: ', int(time))
rate = input()
print('\nEnter the Rate (2% = 0.02) you will collect on your investment: ', float(rate))
interest = (float(principal) * float(rate)) * int(time)
final_value = float(principal) + float(interest)
print('\nThe Final Value of your investment will be: $%.2f' % final_value)`
所以我需要的美元數額的輸出有一個逗號(27,500.00 $),但我不知道如何做到這一點。我在這個網站和其他網站上看到了一些解決方案,但我無法讓他們工作。請有人可以幫助我嗎?
您是否試過'「{:,}」.format(value)'from https://stackoverflow.com/questions/1823058/how-to-print-number-with-commas-as-thousands-分離器 – deltatango
是的,我無法讓它工作;我只在我的第四周上課,所以你們都必須忍受我。 :P在檢查了下面的解決方案之後,我看到我做錯了什麼。感謝大家! –