[Tutor] Help on Python

Mats Wichmann mats at wichmann.us
Tue Oct 15 11:38:35 EDT 2019


On 10/14/19 6:07 PM, Tyson Barber wrote:
> 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.

Your comment on having tried spacing changes suggests you haven't yet 
grasped how it works, so let's try:

within a file, a code block is a piece of Python code that can be 
executed together - one or more statements.  For example, when you do a 
condition test (if statement), and the test evaluates true, then the 
things you do in that case are a "code block".  code blocks are indented 
- it's part of the Python syntax.  Your hint that a block is about to 
occur is a statement ending with a colon, so

if color == "red":
    do something that relates to that
    and another line
    and one more
this is no longer part of the code block.

that's the only time you should be indenting, so your other indents 
above are incorrect (some of the other replies have pointed this out as 
well).  code aligns consistently, then when there's a block, indent it; 
blocks can nest so there can be another layer of indentation, and another.

hope that helps clear things up a bit...

you have several erorrs above - most have already been pointed out. 
parentheses have to match, so the places you have two opening and one 
closing paren will always be syntax errors.




More information about the Tutor mailing list