7 Replies - 839 Views - Last Post: 24 June 2016 - 10:15 AM Rate Topic: -----

#1 kobs20   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 07-May 16

Unsupported Operand Types Error

Posted 23 June 2016 - 02:26 PM

"""KIT COMPLETION ESTIMATOR
BY: JACOB KOBS
DATE: 6/23/2016
DATE OF MODIFICATION: 6/23/2016
PURPOSE OF PROGRAM: TO ESTIMATE WORK ORDER COMPLETION TIME BASED ON HOURLY
PRODUCTION RATE, PALLET NUMBER, AND HOURS WORKED SO FAR.
___________________________________________________________________________"""

def main():
    palletCompleted = 0
    palletNumber = 0
    inputMenu = ""
    inputUserMenu = "1", "2"
    onTime = "yes" or "no"
    yes = "You are ahead of schedule. Keep up the great work!"
    no = "You are behind in terms of average work order completion time. Please speed up."
    hoursWorked = 0
    timeTillCompletion = 0
    hourlyCompletion = 0
    timeDue = 26
    pointTwoValue = int(.2)
    completionNumber = int(52)
    endProgram = "2"
    endProgram = raw_input("Press 1 to continue with the program or 2 to end it: ")
    while (endProgram != "2"):
        if (endProgram == "1"):
             print "You are being directed to the kit estimator program."
             palletNumber = palletNum(palletNumber)
             palletCompleted = palletComp(palletCompleted)
             hoursWorked = hoursWork(hoursWorked)
             onTime = onT(completionNumber, pointTwoValue, timeDue, yes, no, palletCompleted, palletNumber, hoursWorked, hourlyCompletion, onTime)
             break
             print "The program will now end."
        else:
            print "The input that you have entered is not valid. Please try again."
            endProgram = raw_input("Press 1 to continue with the program or 2 to end it: ")



def palletNum(palletNumber):
    palletNumber = raw_input("Please input what pallet you're currently on: ")
    if (palletNumber > "52" or palletNumber < "0"):
        print "You have entered an invalid number. Please try again."
        palletNumber = raw_input("Please input what pallet you're currently on: ")
    else:
        return palletNumber


def palletComp(palletCompleted):
    palletCompleted = raw_input("Input how many pallets you complete in an hour: ")
    if (palletCompleted > "8" or palletCompleted < "1"):
        print "The amount that you have answered doesn't register in the system."
        palletCompleted = raw_input("Input how many pallets you complete in an hour: ")
    else:
        return palletCompleted

def hoursWork(hoursWorked):
    hoursWorked = raw_input("Please enter a rough estimate of how long you have worked thus far: ")
    if (hoursWorked > "40" and hoursWorked < "0"):
        print "Your input doesn't follow our criteria. Enter a number between 0 and 40."
        hoursWorked = raw_input("Please enter a rough estimate of how long you have worked thus far: ")
    else:
        return hoursWorked

def onT(completionNumber, pointTwoValue, timeDue, yes, no, palletCompleted, palletNumber, hoursWorked, hourlyCompletion, onTime):
    palletCompleted = palletNumber + palletCompleted
    hourlyCompletion = palletCompleted * pointTwoValue
    timeTillCompletion = (completionNumber - palletNumber) * hourlyCompletion

main()



This is the error that I'm getting:
 File "C:/Users/jkobs/Desktop/Pallet Completion.py", line 68, in onT
    timeTillCompletion = (completionNumber - palletNumber) * hourlyCompletion
TypeError: unsupported operand type(s) for -: 'int' and 'str' 


What I want the program to do is subtract the pallet number that the user is on from the completion number (52) and multiply it by hourly completion.

Is This A Good Question/Topic? 0
  • +

Replies To: Unsupported Operand Types Error

#2 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 406
  • View blog
  • Posts: 1,312
  • Joined: 27-December 13

Re: Unsupported Operand Types Error

Posted 23 June 2016 - 02:48 PM

palletNumber is given as input in line 44, thus type is 'string'
You need to modify line 68 to
timeTillCompletion = (completionNumber - int(palletNumber)) * hourlyCompletion


Was This Post Helpful? 0
  • +
  • -

#3 kobs20   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 07-May 16

Re: Unsupported Operand Types Error

Posted 23 June 2016 - 03:17 PM

Thank you DK for you quick response, however; I am now stuck on another problem.
 Press 1 to continue with the program or 2 to end it: 5
The input that you have entered is not valid. Please try again.
Press 1 to continue with the program or 2 to end it: 6
The input that you have entered is not valid. Please try again.
Press 1 to continue with the program or 2 to end it: 8
The input that you have entered is not valid. Please try again.
Press 1 to continue with the program or 2 to end it: 7
The input that you have entered is not valid. Please try again.
Press 1 to continue with the program or 2 to end it: 6
The input that you have entered is not valid. Please try again.
Press 1 to continue with the program or 2 to end it: 5
The input that you have entered is not valid. Please try again.
Press 1 to continue with the program or 2 to end it: 7
The input that you have entered is not valid. Please try again.
Press 1 to continue with the program or 2 to end it: 5
The input that you have entered is not valid. Please try again.
Press 1 to continue with the program or 2 to end it: 1
You are being directed to the kit estimator program.
Please input what pallet you're currently on: 14
Input how many pallets you complete in an hour: 2
Please enter a rough estimate of how long you have worked thus far: 7
You have approximately:  0 hours until the work order will be completed.


As you can see, for some reason, the program is always outputting 0 hours as an answer. Here is the code for the program:
 """KIT COMPLETION ESTIMATOR
BY: JACOB KOBS
DATE: 6/23/2016
DATE OF MODIFICATION: 6/23/2016
PURPOSE OF PROGRAM: TO ESTIMATE WORK ORDER COMPLETION TIME BASED ON HOURLY
PRODUCTION RATE, PALLET NUMBER, AND HOURS WORKED SO FAR.
___________________________________________________________________________"""

def main():
    palletCompleted = 0
    palletNumber = 0
    inputMenu = ""
    inputUserMenu = "1", "2"
    onTime = "yes" or "no"
    yes = "You are ahead of schedule. Keep up the great work!"
    no = "You are behind in terms of average work order completion time. Please speed up."
    hoursWorked = 0
    timeTillCompletion = 0
    hourlyCompletion = 0
    timeDue = 26
    pointTwoValue = int(.2)
    completionNumber = int(52)
    printModule = ""
    endProgram = "2"
    endProgram = raw_input("Press 1 to continue with the program or 2 to end it: ")
    while (endProgram != "2"):
        if (endProgram == "1"):
             print "You are being directed to the kit estimator program."
             palletNumber = palletNum(palletNumber)
             palletCompleted = palletComp(palletCompleted)
             hoursWorked = hoursWork(hoursWorked)
             onTime = onT(completionNumber, pointTwoValue, timeDue, yes, no, palletCompleted, palletNumber, hoursWorked, hourlyCompletion, onTime)
             printModule = printMod(timeTillCompletion, printModule)
             break
             print "The program will now end."
        else:
            print "The input that you have entered is not valid. Please try again."
            endProgram = raw_input("Press 1 to continue with the program or 2 to end it: ")



def palletNum(palletNumber):
    palletNumber = raw_input("Please input what pallet you're currently on: ")
    if (palletNumber > "52" or palletNumber < "0"):
        print "You have entered an invalid number. Please try again."
        palletNumber = raw_input("Please input what pallet you're currently on: ")
    else:
        return palletNumber


def palletComp(palletCompleted):
    palletCompleted = raw_input("Input how many pallets you complete in an hour: ")
    if (palletCompleted > "8" or palletCompleted < "1"):
        print "The amount that you have answered doesn't register in the system."
        palletCompleted = raw_input("Input how many pallets you complete in an hour: ")
    else:
        return palletCompleted

def hoursWork(hoursWorked):
    hoursWorked = raw_input("Please enter a rough estimate of how long you have worked thus far: ")
    if (hoursWorked > "40" and hoursWorked < "0"):
        print "Your input doesn't follow our criteria. Enter a number between 0 and 40."
        hoursWorked = raw_input("Please enter a rough estimate of how long you have worked thus far: ")
    else:
        return hoursWorked

def onT(completionNumber, pointTwoValue, timeDue, yes, no, palletCompleted, palletNumber, hoursWorked, hourlyCompletion, onTime):
    palletCompleted = palletNumber + palletCompleted
    hourlyCompletion = palletCompleted * pointTwoValue
    timeTillCompletion = (completionNumber - int(palletNumber)) * hourlyCompletion
    
    return timeTillCompletion


def printMod(timeTillCompletion, printModule):
    print "You have approximately: ", timeTillCompletion, "hours until the work order will be completed."
    
main()

 

Was This Post Helpful? 0
  • +
  • -

#4 CurlyJoe   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 97
  • Joined: 19-September 13

Re: Unsupported Operand Types Error

Posted 23 June 2016 - 04:37 PM

Quote

the program is always outputting 0 hours as an answer
What does this mean, outputting where, and an answer for what?
Was This Post Helpful? 0
  • +
  • -

#5 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 406
  • View blog
  • Posts: 1,312
  • Joined: 27-December 13

Re: Unsupported Operand Types Error

Posted 24 June 2016 - 05:24 AM

Look at line 21 - what do you think is the value of pointTwoValue ?
This value is then used in line 69 etc.
Was This Post Helpful? 0
  • +
  • -

#6 kobs20   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 07-May 16

Re: Unsupported Operand Types Error

Posted 24 June 2016 - 07:08 AM

The value is .2, but I keep getting 0 as an answer no matter what the user inputs are.
Was This Post Helpful? 0
  • +
  • -

#7 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2616
  • View blog
  • Posts: 4,173
  • Joined: 21-June 11

Re: Unsupported Operand Types Error

Posted 24 June 2016 - 08:23 AM

View Postkobs20, on 24 June 2016 - 04:08 PM, said:

The value is .2


What are you basing that statement on? I say the value is 0.
Was This Post Helpful? 0
  • +
  • -

#8 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 406
  • View blog
  • Posts: 1,312
  • Joined: 27-December 13

Re: Unsupported Operand Types Error

Posted 24 June 2016 - 10:15 AM

Try print the variable as new line 22....
print(pointTwoValue)

This post has been edited by DK3250: 24 June 2016 - 01:42 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1