我正在嘗試創建一個簡單的折扣計算器。這是我的變量:如何在Python中「粘」兩個數字?
percentage = float(raw_input('Percentage: '))
price = float(raw_input('Price: $'))
discount = price*percentage
finalPrice = price - discount
此刻,我要輸入「0.50」來計算50%的折扣,但是,我想簡單地輸入「50」。有沒有簡單的方法來添加「0」。輸入以百分比形式輸入的數字,如'0.' + 'percentage'
,以便得到'0.percentage'
?
棒在一些前面的0,得到0.9其中用戶指9%。失敗。 –
強制性的:請不要使用'浮動'的錢。改爲使用'decimal.Decimal'。 –