擅长:python、mysql、java
<p>不管我输入了多少次零/非数字,我最终得到了以下结果:</p>
<pre><code># *** METHOD ***
def calc(x):
years = 72/x
print("Your investment will double in " + str(years) + " years.")
# *** USER INPUT ***
while True:
try:
r = float(input("What is your rate of return?: "))
if r < 1:
while r < 1:
r = float(input("Rate can't be less than 1! What is your rate of return?: "))
break
except:
print("ERROR: please input a number!")
calc(r)
</code></pre>