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?
input()for this, since it evaluates arbitrary code. Example. Instead, useint(raw_input(...)),float(raw_input(...)),str(raw_input(...)), etcinput()as taking a line of code from the user and evaluating it, much like the python console. Basically anything that you can put after asome_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 aValueError), andfloat()will convert the string to a floating-point number (read: a number with a decimal point). I'm not sure why I includedstr()in there now, since that'l just convert the string ... to a string.name_or_whatever = raw_input('What is thy name?').