Good morning, I'm learning some basic programming and fundamentals and I am having a hard time troubleshooting why a certain part of my code is not working. In my "calcTotal" function, my If, Else statements do not seem to be working. The program runs through, but the output is always 0's and no matter what the program reports that the cell phone minutes were not over minutesAllowed, even when you say that minutesUsed is more than allowed.

Any help would be greatly appreciated. I think my idententations are right, I just don't understand what I am overlooking.

Thanks in advance.

#Cellphone Minute Calculator

#main function
def main():

    minutesAllowed = 0
    minutesUsed = 0
    totalDue = 0
    minutesOver = 0
    endProgram = "no"
   
    while endProgram == "no":
        #functions/modules
        getAllowed(minutesAllowed)

        getUsed(minutesUsed)

        calcTotal(minutesAllowed, minutesOver, minutesUsed, totalDue)

        printData(minutesAllowed, minutesUsed, totalDue, minutesOver)

        endProgram = raw_input('Do you want to end program? (Enter yes or no): ')

        while not (endProgram == 'yes' or endProgram == 'no'):
            print 'Please enter a yes or no'
            endProgram = raw_input('Do you want to end program? (Enter no to process a new set of scores): ')

def getAllowed(minutesAllowed):
    minutesAllowed = input("Enter minutes allowed (Between 200 - 800): ")

    while(minutesAllowed < 200 or minutesAllowed >800):
        print "You must enter between 200 and 800"
        minutesAllowed = input("Enter minutes allowed (Between 200 - 800):")

    return minutesAllowed

def getUsed(minutesUsed):
    minutesUsed = input("Enter minutes used: ")

    while(minutesUsed <0):
        print "You must enter 0 or greater"
        minutesUsed = input("Enter minutes used: ")

    return minutesUsed

def calcTotal(minutesAllowed, minutesOver, minutesUsed, totalDue):
    
    extra = 0
    
    if minutesUsed <= minutesAllowed:
        totalDue =74.99
        minutesOver = 0
        print "You were not over your minutes for the month."        
    else:
        minutesOver = minutesUsed - minutesAllowed
        extra = minutesOver * .20
        totalDue = 74.99 + extra
        print "You were over your minutes by ",minutesOver
        
    return totalDue, minutesOver

def printData(minutesAllowed, minutesUsed, totalDue, minutesOver):
    print "-------Monthly Use Report ---------"
    print "Minutes allowed were ",minutesAllowed
    print "Minutes used were ",minutesUsed
    print "Minutes over were ",minutesOver
    print "Total due is $",totalDue

    
main()

Hi,
on #35 you provided a return statement. That is good but return will not print a value. you must either use a print there or use a print on #14 on the function.

Mixing print and return can get confuse noob. optimise that part. ok ?
;)

Works fine for me. Note that you only have to pass minutes allowed and minutes used to the function.

def calc_total(minutesAllowed, minutesUsed):
 
    extra = 0
 
    if minutesUsed <= minutesAllowed:
        totalDue =74.99
        minutesOver = 0
        print "You were not over your minutes for the month."        
    else:
        minutesOver = minutesUsed - minutesAllowed
        extra = minutesOver * .20
        totalDue = 74.99 + extra
        print "You were over your minutes by ",minutesOver
 
    return totalDue, minutesOver

print calc_total(100, 90)
print calc_total(100, 110)
"""
You were not over your minutes for the month.
(74.99, 0)

You were over your minutes by  10
(76.99, 10)
"""

And what do you think does/does not happen here

print minutesAllowed, minutesOver, minutesUsed, totalDue
        calcTotal(minutesAllowed, minutesOver, minutesUsed, totalDue)
        print minutesAllowed, minutesOver, minutesUsed, totalDue

First of all, thanks for the replies, it's appreciated. However, I'm still scratching my head a bit.

To answer woooee, in line 1, I would think it would print minutesAllowed and minutesUsed using the data the user inputed while using the declared values of totalDue and minutesOver (which at this point would be zero). In line 2 it would call the calcTotal function. Line 3 would then print the new values.

I get the same thing when I put in the print calcTotal lines as you did, but, I am trying to call those functions from inside the while loop. The excercise is in validation loops so I have to keep the minutesAllowed within the range.

This what I get when I run the program:


Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Enter minutes allowed (Between 200 - 800): 300
Enter minutes used: 200
0 0 0 0
You were not over your minutes for the month.
0 0 0 0
-------Monthly Use Report ---------
Minutes allowed were 0
Minutes used were 0
Minutes over were 0
Total due is $ 0
Do you want to end program? (Enter yes or no):

I got it! The problem was in my function calls. I wasn't setting the variables equal to the functions. I understand now. Thanks for getting me on the right path!

well i told you about that.... ;)

Yes you did, I'm still learning the terminology as well so I didn't pick up on it right away. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.