[Tutor] I don't know why this program doesn't run
d at davea.name
Sat Sep 22 02:17:59 CEST 2012
Hi, you forgot to do a reply-all, so it didn't go to the list. I'm
correcting that now, so don't worry about it. if your email doesn't
support reply-all, then just add a cc of tutor at python.org
On 09/21/2012 08:09 PM, Gina wrote:
> On 9/21/2012 6:47 PM, Dave Angel wrote:
>> On 09/21/2012 07:34 PM, Gina wrote:
>>> I don't know why this program doesn't run, but if you know, please
>>> tell me.
>> So what happens when you try? "Doesn't run" covers a multitude of
>> First one:
>> python Car Salesperson.py
>> python: can't open file 'Car': [Errno 2] No such file or directory
>> davea at think:~/temppython$
>> The fix for this one is to put quotes around the script name. Or to
>> escape the blanks. Or even better to rename the file so it doesn't have
>> spaces in it.
>> Please be specific. You're running some OS, you launch some particular
>> version of Python, you give it some commandline, and you get some
>> unexpected result. Use a lot of copy/paste and it's not too painful.
> I have version 3 of python.
> it will let me type in the type of car and then enter
> then i type in the base price and when i hit enter, it says error
The problem is in your input statement: base_price = input("What is the
input (on Python version 3.x) always returns a string. Sometimes that's
what you want, sometimes it's not. In this case, just change to:
base_price = int(input("What is the base price?"))
> This is the error message:
> tax = base_price / 25
> TypeError: unsupported operand type(s) for /: 'str' and 'int'
> I tried adding int() in front of base_price but it still didn't work
Again, please be specific. If you really tried this:
tax = int() base_price /25
then it naturally won't work. But if you tried
tax = int(base_price) / 25
it should have worked. What error did you get? Did it give the wrong
answer, or another exception traceback?
Anyway, I showed you my preference. Convert data to their final type as
soon as possible after getting it from the user. Not later when you're
trying to use it.
More information about the Tutor