<p>你面临的问题是双重的。你知道吗</p>
<p>原始输入的输入类型是字符串,没有错误,因为</p>
<pre><code>print "tata" * 2 # tatatata
</code></pre>
<p>是一个有效的字符串表示法-一直乘以0,因此得到空字符串:<code>''</code>。你知道吗</p>
<p>其次,需要调整除法以返回浮点值。你知道吗</p>
<p>固定代码:</p>
<pre><code>def get_income(): # See Prunes post
num = float(raw_input("Enter your Income: "))
print "Your income is: %d " % int(num)
return num
income= get_income()
print(type(income))
def bills_expenses():
bills_kitty=0
bills_kitty=(income*(55/100.0))
return ("Your bills kitty should have: ", bills_kitty)
def long_term_savings():
long_term_savings_kitty=(10/100.0)*income
return "Your long term kitty should have: ", long_term_savings_kitty
def play_and_leisure():
play_and_leisure_kitty=(10/100.0)*income
return "Your play and leisure kitty should have: " , play_and_leisure_kitty
def education_personal_growth():
education_personal_growth_kitty=(10/100.0)*income
return "Your personal growth kitty should have: ", education_personal_growth_kitty
def pay_myself_Financial_fredom():
pay_myself_Financial_fredom_kitty=(10/100.0)*income
return "Your pay yourself kitty should have: ", pay_myself_Financial_fredom_kitty
def give_back_to_the_community():
give_back_to_the_community_kitty=(5/100.0)*income
return "Your giving back kitty should have: " , give_back_to_the_community_kitty
bills=bills_expenses()
long_term = long_term_savings()
play=play_and_leisure()
education=education_personal_growth()
mine=pay_myself_Financial_fredom()
give=give_back_to_the_community()
print bills
print long_term
print play
print education
print mine
print give
</code></pre>
<p>输出:</p>
<pre><code>Enter your Income: Your income is: 200
<type 'float'>
('Your bills kitty should have: ', 110.00000000000001)
('Your long term kitty should have: ', 20.0)
('Your play and leisure kitty should have: ', 20.0)
('Your personal growth kitty should have: ', 20.0)
('Your pay yourself kitty should have: ', 20.0)
('Your giving back kitty should have: ', 10.0)
</code></pre>
<p>您将得到浮点不准确性-请参见<a href="https://stackoverflow.com/questions/588004/is-floating-point-math-broken">Is floating point math broken?</a>-您可以使用<code>round(3.2222,2)</code>四舍五入到2位小数。你知道吗</p>