[Tutor] Help on Python
Sibylle Koczian
nulla.epistola at web.de
Tue Oct 15 07:34:41 EDT 2019
Am 15.10.2019 um 02:07 schrieb Tyson Barber:
> Hello Tutor,
>
> I am new to Python and had a question.
>
> incomevar = (input("Please enter the income: ")
> income = int(incomevar)
> costvar = int(input("Please enter the cost: ")
> cost = int(costvar)
> if income >= cost :
> print (income - cost == profit)
> else income < cost :
> print (cost - income == loss)
>
> I have tried many things for this to work, including changing the variable
> names, spacing issues. Nothing seems to work and I am quite confused. I
> honestly don't even know if this is the right email address to send this to.
>
It is.
In addition to the advice you already got: the line
else income < cost :
is syntactically wrong. It would be correct to write
elif income < cost:
but the elif isn't necessary. Income and cost are numbers, so either
income >= cost or income < cost. No third possibility. So you can and
should simply write
if income >= cost:
# ...
else:
# ...
Your print statements won't run either, because the variables profit and
loss aren't defined.
More information about the Tutor
mailing list