Interest Calculator looping issue Python
<p>beginner here. I've made an interest calculator program to help me with my loans of different sorts. I'm having two issues to finalize my program. Here's the program. I tried looking up the problems but I wasn't sure how to word it so I thought I'd just ask a question in total.</p>

<pre><code>x=1
while x==1:
    import math
    loan=input("Enter Loan amount: ")
    rate=input("Enter rate: ")
    if rate.isalpha() or loan.isalpha():
        print("Hey that's not a number!")
        break
    rate=rate.replace("%","")
    loan=float(loan)
    rate=float(rate)*0.01
    amount1y=round(loan*(math.e**(rate*1)),2)
    amount5y=round(loan*(math.e**(rate*5)),2)
    amount10y=round(loan*(math.e**(rate*10)),2)
    monthlypay=round(amount1y-loan,2)
    print("Year 1 without pay: " + str(amount1y))
    print("Year 5 without pay: " + str(amount5y))
    print("Year 10 without pay: " + str(amount10y))
    print("Amount to pay per year: " + str(monthlypay))
    print("Want to do another? Y/N?")
    ans=input('')
    ans=ans.lower()
    y=True
    while y==True:
        if ans=="n" or ans=="no":
            x=0
            break
        elif ans=="y" or ans=="yes":
            y=False
        else:
            print("You gotta tell me Yes or No fam...")
            print("I'll just assume that mean's yes.")
            break
</code></pre>

<p>My issue is in two locations. First during the</p>

<pre><code>if rate.isalpha() or loan.isalpha():
        print("Hey that's not a number!")
        break
</code></pre>

<p>How do I write this so that instead of it ending the program all together, it instead restarts from the top until they put in a number. Also as a side just for fun and knowledge. Lets say they enter text three times in a row, and at that point it just executes the program how would I go about doing that also?
Finally during this part of the code:</p>

<pre><code> while y==True:
        if ans=="n" or ans=="no":
            x=0
            break
        elif ans=="y" or ans=="yes":
            y=False
        else:
            print("You gotta tell me Yes or No fam...")
            print("I'll just assume that mean's yes.")
            break
</code></pre>

<p>the else at the end, without that break, will continue printing "You gotta tell me Yes or No fam..." forever. How do I make it so that instead of breaking the while statement, it'll just restart the while statement asking the question again?</p>

<p>Thanks for your help!
P.S. This is python 3.4.2</p>

<p>You make an infinite loop, that you <code>break</code> out of when all is well. Simplified:</p>

<pre><code>while True:
    x_as_string = input("Value")
    try:
         x = float(x_as_string)
    except ValueError:
         print("I can't convert", x_as_string)
    else:
         break
</code></pre>

<p>It is easier to ask forgiveness than permission: You try to convert. If conversion fails you print a notice and continue looping <code>else</code> you <code>break</code> out of the loop.</p>

python