TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'

Hoo7on

I'm trying to make a program that calculates how much it costs to miss a class. I take in variables tuition, number of courses, and number of weeks in a semester; it then plots the results (using python 2.7). Here's the code I've been working on:

import matplotlib.pyplot as plot

def calculations(t, c, w, wk):

    two_week = (((t/c)/w)/2)*wk
    three_week = (((t/c)/w)/3)*wk
    return two_week, three_week

def main():
    tuition = float(raw_input('Tuition cost (not including fees): '))
    courses = int(raw_input('Number of courses: '))
    weeks = int(raw_input('Number of weeks in the semester: '))
    x_axis = range(0,10)
    y_axis = []
    y_axis2 = []
    for week in x_axis:
        cost_two, cost_three = calculations(tuition, courses, weeks, week)
        y_axis += [cost_two]
        y_axis2 += [cost_three]

    plot.plot(x_axis, y_axis ,marker='o', label='course meets 2x a week', color='b')
    plot.plot(x_axis, y_axis2,marker='o', label='course meets 3x a week', color='g')
    plot.xlabel('number of missed classes')
    plot.ylabel('cost ($)')
    plot.title('Tuition: %.2f Courses: %d Weeks in a semester: %d\n Created by <MyName>') %(tuition, courses, weeks)
    plot.legend()
    plot.xticks(x_axis)
    plot.xlim(0,x_axis[-1]+1)
    plot.yticks(y_axis)
    plot.ylim(0, y_axis[0]+1)
    plot.grid()
    plot.show()
    plot.savefig('missing-class-cost.pdf')

main()

However, whenever I run my program, I receive the following error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 36,     in <module>
  File "C:\Program Files (x86)\Wing IDE 101 4.1\src\debug\tserver\_sandbox.py", line 26, in main
TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'

Line 26 is in reference to this line of code:

plot.title('Tuition: %.2f Courses: %d Weeks in a semester: %d\n Created by <MyName>') %(tuition, courses, weeks)

I'm assuming it's due to some math, but I didn't use a tuple in the whole program, so I'm kind of at a loss.

Any help is appreciated, thanks.

DSM

Your parentheses are in the wrong place. You probably want

plot.title('Tuition: [...]' %(tuition, courses, weeks))

instead. Right now, you're doing

plot.title('Tuition: [...]') %(tuition, courses, weeks)

so you're calling plot.title, which is returning a Text object, and then you're trying to call % on that, which gives rise to the error message:

TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'

which hopefully should make more sense now. Even though you say "I didn't use a tuple in the whole program", that's exactly what (tuition, courses, weeks) is.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'

From Dev

TypeError: unsupported operand type(s) for |: 'tuple' and 'bool'

From Dev

TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

From Dev

TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' with random generator?

From Dev

Unsupported operand types 'NoneType'

From Dev

Django unsupported operand types

From Dev

unsupported operand types for //: 'str', 'int'

From Dev

unsupported operand types for * : 'float' and 'decimal'

From Dev

TypeError: unsupported operand type in Python

From Dev

CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

From Dev

CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

From Dev

unsupported operand type(s) for +: 'int' and 'tuple'

From Dev

Python: unsupported operand type(s) for /: 'tuple' and 'float'

From Dev

Unsupported operand types for bitwise exclusive OR in Python

From Dev

TypeError: unsupported operand type(s)s for +: 'StringVar' and 'str' // Create a text file

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'list' when trying to split a text file

From Dev

TypeError: unsupported operand type(s) for +=: 'int' and 'list'

From Dev

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

From Dev

TypeError: unsupported operand int and NoneType? Python

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

From Dev

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

From Dev

TypeError: unsupported operand type(s) for |: 'int' and 'str'

From Dev

TypeError: unsupported operand type(s) for |: 'list' and 'list'

From Dev

TypeError: unsupported operand type(s) for -: 'list' and 'list'

From Dev

TypeError: unsupported operand type(s) for +: 'decimal' and 'float'

From Dev

TypeError: unsupported operand type(s) for +: 'int' and 'Element'

From Dev

TypeError: unsupported operand type(s) for //: 'int' and 'graph'

From Dev

TypeError: unsupported operand type(s) for -: 'module' and 'LinearSegmentedColormap'

Related Related

  1. 1

    TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'

  2. 2

    TypeError: unsupported operand type(s) for |: 'tuple' and 'bool'

  3. 3

    TypeError: unsupported operand type(s) for +: 'float' and 'tuple'

  4. 4

    TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' with random generator?

  5. 5

    Unsupported operand types 'NoneType'

  6. 6

    Django unsupported operand types

  7. 7

    unsupported operand types for //: 'str', 'int'

  8. 8

    unsupported operand types for * : 'float' and 'decimal'

  9. 9

    TypeError: unsupported operand type in Python

  10. 10

    CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

  11. 11

    CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

  12. 12

    unsupported operand type(s) for +: 'int' and 'tuple'

  13. 13

    Python: unsupported operand type(s) for /: 'tuple' and 'float'

  14. 14

    Unsupported operand types for bitwise exclusive OR in Python

  15. 15

    TypeError: unsupported operand type(s)s for +: 'StringVar' and 'str' // Create a text file

  16. 16

    TypeError: unsupported operand type(s) for +: 'int' and 'list' when trying to split a text file

  17. 17

    TypeError: unsupported operand type(s) for +=: 'int' and 'list'

  18. 18

    TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

  19. 19

    TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

  20. 20

    TypeError: unsupported operand int and NoneType? Python

  21. 21

    TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

  22. 22

    TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

  23. 23

    TypeError: unsupported operand type(s) for |: 'int' and 'str'

  24. 24

    TypeError: unsupported operand type(s) for |: 'list' and 'list'

  25. 25

    TypeError: unsupported operand type(s) for -: 'list' and 'list'

  26. 26

    TypeError: unsupported operand type(s) for +: 'decimal' and 'float'

  27. 27

    TypeError: unsupported operand type(s) for +: 'int' and 'Element'

  28. 28

    TypeError: unsupported operand type(s) for //: 'int' and 'graph'

  29. 29

    TypeError: unsupported operand type(s) for -: 'module' and 'LinearSegmentedColormap'

HotTag

Archive