[Tutor] Help on Python

Tyson Barber tysonwbarber at gmail.com
Tue Oct 15 20:20:28 EDT 2019


Tyson Barber <tysonwbarber at gmail.com>
7:46 PM (32 minutes ago)
to *alan.gauld*
Hi Python Help,

Sorry about the confusion of my last email, this is my first time using
this method of help.

I have tweaked the code slightly to look like this:

income = (input("Please enter the income: "))
cost = int(input("Please enter the cost: "))
if income >= cost :
        print (income - cost == profit)
else:
    income < cost :
        print (cost - income == loss)

in the line after the else statement, it is giving me an error message of
invalid syntax (where the red is).

It does not give me a syntax error for the other line that is similar to it
earlier (highlighted in yellow).

Is it still a spacing issue, or is it possibly something with the text?

Thank you,

Tyson Barber

On Tue, Oct 15, 2019 at 8:21 PM Alan Gauld <alan.gauld at yahoo.co.uk> wrote:

> You have to use reply-All or reply-List to reply to the list,
> otherwise it just goes to the original sender.
>
>
> On 16/10/2019 00:46, Tyson Barber wrote:
> > I have tweaked the code slightly to look like this:
> >
> > income = (input("Please enter the income: "))
>
> You haven't converted to int. Use the same pattern
> you use in the next line.
>
> > cost = int(input("Please enter the cost: "))
> > if income >= cost :
> > ?? ?? ?? ?? print (income - cost == profit)
>
> Your print is still trying to print the boolean result of the expression
>
> income - cost == profit
>
> And you have not defined profit yet so this will
> yield errors if it ever gets this far.
>
>
> > else:
> > ?? ?? income < cost :?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
>
> The else syntax is simply
>
> else:
>    # code here that gets executed when the preceding if fails
>    # You cannot have an expression with a colon on its own.
>    # That's invalid Python.
>
>
> > ?? ?? ?? ?? print (cost - income == loss)
>
> Same as above you are trying to print the boolean expression result.
>
> You probably want to add a string here like:
>
> print ("cost - income ==", cost-income)
>
>
> Or on two lines:
>
> loss = cost-income
> print(loss)
>
> > in the line after the else statement, it is giving me an error message
> > of invalid syntax (where the red is).
>
> This is a text only list so binary attachments get stripped out.
> You need to paste the full error text into the mail message.
> Starting with the line:
>
> Traceback (most recent call last):
> ...
>
> > It does not give me a syntax error for the other line that is similar to
> > it earlier (highlighted in yellow).
>
> I can't see the colours but expect it is that else statement
>  - or more precisely the expression following it.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>


More information about the Tutor mailing list