0

The first function is used to ask for an input that is numerical and has not more than 1 decimal point. the first function checks to see if it is numerically valid, and the second function takes a cash amount and displays the minimum amount of coins you would get back. I am having trouble getting my first function to use the new inputs in the second function. It askes for the input but uses the original errored one. If anyone could help, Thank you

import math

def isFloat(get_float):
    check = get_float.split(".")
    length = len(check)
    for i in check:
        try:
            get_float = input("Error: Re Enter Amount Owed $ ")
        except ValueError:
            print("Sorry, that is invalid")
        if length > 2:
            return isFloat(get_float)
        elif length == 2:
            if check[0].isnumeric() == False or check[1].isnumeric() == False:
                return isFloat(get_float)
            if check[0].isnumeric() == True and check[1].isnumeric() == True:
                return True
        elif length == 1:
            if not i.isnumeric():
                return isFloat(get_float)
        else:
            return True


def cash(get_float):
    negative = get_float.count("-")
    while negative > 0:
        get_float = input("Invalid syntax ")
        negative = cost.count("-")
    Quarters = 0.25
    Dimes = 0.10
    Nickels = 0.05
    Pennies = 0.01
    list = {Quarters: 0, Dimes: 0, Nickels: 0, Pennies: 0}
    owed = float(get_float)
    rounded = round(owed * 100)
    print("Change Owed back to you: " + "$" + str(rounded / 100))
    if get_float < get_float:
        print("InsufficientFunds")
    else:
        for changeType in list:
            Amount = max(0, owed // changeType)
            owed = owed - Amount * changeType
            list[changeType] = int(Amount)
        print("Minimum coins given back -", list)


get_float = input("Amount Owed $")
isFloat(get_float)
cash(get_float)
AceHigh
  • 11
  • 3

1 Answers1

0

You might want to recurse the function where you take input if user has entered wrong input. In the if statement else part where the program will go if user input is wrong, add return FUNCTIONNAME() at last where FUNCTIONNAME is the function name and remove breaks there

Wasif
  • 14,755
  • 3
  • 14
  • 34
  • I edited the code, I'm still not quite sure what I'm doing wrong but I think I'm getting closer, did I do the add ```return FUNCTIONNAME()`` part correctly? and I tried to recurse it as well but now it says my original input it incorrect and it takes the second one. Also, I had the breaks in there by mistake so I changed that. – AceHigh Oct 11 '20 at 03:46