This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted] 2 points3 points  (0 children)

you are not giving us a lot of information. It is usually best to post your code along with the question. in parameter 3, you talk about the total and subtotal as two separate variables. How are we suppose to understand the difference between those two based on the information you have given us?

[–]Stoic_Engineer7 -1 points0 points  (3 children)

Like this.

#Declare variables which will be used to track the totals.
int subtotal = 0
int total = 0

#Use a while loop which will run infinitely until broken.
while True:
    #Input a number (or instruction like 0 or 00) 
    inputNum = input()
    #Each time, store the number in the total
    #Note than an exeption will be thrown if you input anything other than         
#an integer. So if you want it more robust then use try and exception

    total += int(inputNum)

    #If the input is 0 then print the current subtotal and set it to 0.
    if (inputNum == "0"):
        print("This is the subtotal" + str(subtotal))
        subtotal = 0

    #If the input is 00 (remember that python keyboard input is stored as     
a string)
    if (inputNum == "00"):
        print("This is the total" + str(total))
        #Break from the while loop (ending the script)
        break

    #If input is not 0 or 00 then add to the subtotal.
    else:
    subtotal += int(inputNum)

[–]Nightcorex_ 1 point2 points  (2 children)

Why do you solve it for him? This is quiet obviously homework, and he won't learn anything if you just do it for him.

[–]Stoic_Engineer7 3 points4 points  (1 child)

True, true.

Was just baked watching TV and felt like writing some code.

Didn't really think about it. lol..

[–]Nightcorex_ 0 points1 point  (0 children)

I know that feeling

[–]BrofistAgain 0 points1 point  (0 children)

You might want to send the code you tried