-4

I have a set of different functions that I created and am required to use for a program and I need to figure out how to call them inside one function. Requirements for my code are as follows The Input processing should only be done using functions: getPackage, validPackage, getHours, validHours, and program control constructs. The Calculation Processing should only be done using functions:
calculatePkg_A, calculatePkg_B, calculatePkg_C, and program control constructs. For Output Results you should display the Package Selected, Hours of Usage, and the Amount charged for the month.

getpackage would get an input of A,B,C as an input validPackage would make sure that one of those 3 are selected gettheours would get a float as input valid hours would ensure that the input is between zero and 720 Pkg_A,Pkg_B and Pkg_C are mathematical commands chosen based on the input the user does.

def getPackage(v):
    v=str(input("Choose a package. Must be A, B, or C"))

def validPackage(l):
    if l != "A" or l!="B" or l!="C":
        print("Input must be A,B,C. Please choose a valid package")
        
def getthehours(z):
        z=str(input("Enter a number of hours between 0 and 720"))

def validhours(gethours):
    if gethours<0 or gethours>720:
        print("Invalid number. Numbers must be between 0 to 720")
    else:
        print("GOOD HOUR CHOICE")

def calculatepkg_A(hoursprovided):
    if hoursprovided<50:
        print("Your cost is $15 per month")
    elif hoursprovided>50:
        x=hoursprovided-50
        print((2*x)+15)

def calculatepkg_B(hoursprovided):
    if hoursprovided<100:
        print("Your cost is $20 per month")
    elif hoursprovided>100:
        x=hoursprovided-100
        print((1.5*x)+20)

def calculatepkg_C(hoursprovided):
    if hoursprovided<150:
        print("Your cost is $25 per month")
    elif hoursprovided>=150:
        x=hoursprovided-150
        print((1*x)+25)      
    
def main():
    n=str(input("Choose a package. Must be A, B, or C"))
    l=float(input("Choose a number of hours between 0 and 720"))
    getPackage(n)
    validhours(l)
    if n=="A":
        calculatepkg_A(l)
    elif n=="B":
        calculatepkg_B(l)
    elif n=="C":
        calculatepkg_C(l)
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • `if l != "A" or l!="B" or l!="C":` should use `and`, not `or`. See https://stackoverflow.com/questions/26337003/why-non-equality-check-of-one-variable-against-many-values-always-returns-true – Barmar Oct 31 '22 at 23:09
  • Why does `getPackage()` take `v` as a parameter if it immediately overwrites it with the `input()` call? It needs to return the result -- assigning a parameter variable doesn't assign to the caller's variable. – Barmar Oct 31 '22 at 23:10

1 Answers1

0

getPackage() and getthehours() shouldn't take a parameter, they should return a value.

Then you should call validPackage() and validhours() with the result that was returned. These functions should return a boolean indicating whether the input was valid. You can put these calls into a loop to keep asking until you get a valid response.

def getPackage():
    v=input("Choose a package. Must be A, B, or C")
    return v

def validPackage(l):
    if l not in ("A", "B", "C"):
        print("Input must be A,B,C. Please choose a valid package")
        return False
    else:
        return True
        
def getthehours():
    z=int(input("Enter a number of hours between 0 and 720"))
    return z

def validhours(gethours):
    if gethours<0 or gethours>720:
        print("Invalid number. Numbers must be between 0 to 720")
        return False
    else:
        print("GOOD HOUR CHOICE")
        return True

def calculatepkg_A(hoursprovided):
    if hoursprovided<50:
        print("Your cost is $15 per month")
    elif hoursprovided>50:
        x=hoursprovided-50
        print((2*x)+15)

def calculatepkg_B(hoursprovided):
    if hoursprovided<100:
        print("Your cost is $20 per month")
    elif hoursprovided>100:
        x=hoursprovided-100
        print((1.5*x)+20)

def calculatepkg_C(hoursprovided):
    if hoursprovided<150:
        print("Your cost is $25 per month")
    elif hoursprovided>=150:
        x=hoursprovided-150
        print((1*x)+25)      
    
def main():
    while True:
        n=getPackage()
        if validPackage(n):
            break
        
    while True:
        l=getthehours()
        if validhourse(l):
            break

    if n=="A":
        calculatepkg_A(l)
    elif n=="B":
        calculatepkg_B(l)
    elif n=="C":
        calculatepkg_C(l)

if __name__ == '__main__':
    main()
Barmar
  • 741,623
  • 53
  • 500
  • 612