Skip to main content
  1. About
  2. For Teams
Asked
Viewed 120 times
0

How can I fix this error:

Traceback (most recent call last):
  File "C:\Users\Tony\Desktop\Python\4.py", line 64, in 
    print "YOU PAY: $",(pc-total)
TypeError: unsupported operand type(s) for -: 'str' and 'float'
1
  • 2
    Not only is this a programming question, you are running the program on Windows. Wrong site.
    jordanm
    –  jordanm
    2013-11-02 05:12:01 +00:00
    Commented Nov 2, 2013 at 5:12

1 Answer 1

5

One of the two, pc or total, is a float and the other a string.

As python is strongly typed you would need to cast the string to a float, e.g.:

print "YOU PAY $",(float(pc) - total)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Post as a guest

Required, but never shown

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.