1

I'm new to programming with python (for class) and just can't seem to figure this one out. Here is my code:

department = raw_input
salesQuarterOneThisYear = input
salesQuarterTwoThisYear = input
salesQuarterThreeThisYear = input
salesQuarterFourThisYear = input
salesQuarterOneLastYear = input
salesQuarterTwoLastYear = input
salesQuarterThreeLastYear = input
salesQuarterFourLastYear = input
QUIT = 'ZZZZ'
print 'Enter department name or', QUIT,'to quit:'
raw_input('')

while department != QUIT:
    print 'Enter sales for first quarter this year:'
    salesQuarter1ThisYear = input('')
    print 'Enter sales for second quarter this year:'
    salesQuarter2ThisYear = input('')
    print 'Enter sales for third quarter this year:'
    salesQuarter3ThisYear = input('')
    print 'Enter sales for fourth quarter this year:'
    salesQuarter4ThisYear = input('')
    print 'Enter sales for first quarter last year:'
    salesQuarter1LastYear = input('')
    print 'Enter sales for second quarter last year'
    salesQuarter2LastYear = input('')
    print 'Enter sales for third quarter last year:'
    salesQuarter3LastYear = input('')
    print 'Enter sales for fourth quarter last year:'
    salesQuarter4LastYear = input
    total_this_year = salesQuarterOneThisYear + salesQuarterTwoThisYear + salesQuarterThreeThisYear + salesQuarterFourThisYear
    total_last_year = salesQuarterOneLastYear + salesQuarterTwoLastYear + salesQuarterThreeLastYear + salesQuarterFourLastYear
    print 'Total this year = ',total_this_year
    print 'Total last year = ',total_last_year
    if total_this_year is total_last_year:
        print 'Status = Same'
    if total_this_year > total_last_year:
        print 'Status = Higher'
    if total_this_year < total_last_year:
        print 'Status = Lower'

    print

    print 'Department: ',department
    if total_this_year is total_last_year:
        print 'Status = Same'
    if total_this_year > total_last_year:
        print 'Status = Higher'
    if total_this_year < total_last_year:
        print 'Status = Lower'

    print 'Enter department name or', QUIT,'to quit:'
    raw_input('')

The error I receive is this:

  File ..., line 31, in <module>
    total_this_year = salesQuarterOneThisYear + salesQuarterTwoThisYear + salesQuarterThreeThisYear + salesQuarterFourThisYear
TypeError: unsupported operand type(s) for +: 'builtin_function_or_method' and 'builtin_function_or_method'

Can you please help me with what I'm doing wrong?

4
  • Since you're using python 2.7, I wouldn't use input() for this, since it evaluates arbitrary code. Example. Instead, use int(raw_input(...)), float(raw_input(...)), str(raw_input(...)), etc Commented Mar 21, 2015 at 23:16
  • Thanks Kevin! Question, what are the differences between input(), int(raw_input(...)), float(raw_input(...)), & str(raw_input(...)) Commented Mar 21, 2015 at 23:51
  • Think of input() as taking a line of code from the user and evaluating it, much like the python console. Basically anything that you can put after a some_variable = in python is acceptable. raw_input() gives you the raw string that the user entered. int() will convert that to an integer if it can (otherwise it'll raise a ValueError), and float() will convert the string to a floating-point number (read: a number with a decimal point). I'm not sure why I included str() in there now, since that'l just convert the string ... to a string. Commented Mar 22, 2015 at 17:24
  • If you want just the raw string (like if you're looking for a name or something), use name_or_whatever = raw_input('What is thy name?'). Commented Mar 22, 2015 at 17:24

1 Answer 1

1

You never called input for quarter four:

salesQuarter4LastYear = input

That assigns the function object, not a string. Call the function instead:

salesQuarter4LastYear = input()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.