[Tutor] Help on Python
Alan Gauld
alan.gauld at btinternet.com
Tue Oct 15 11:17:33 EDT 2019
On 15/10/2019 01:07, Tyson Barber wrote:
> Hello Tutor,
Hi, and yes this is the right place.
> I am new to Python and had a question.
You don;t actually ask any question so we'll have to guess.
In future its best to be as specific as possible and always
include any error messages in full so we can see them - they
contain a lot of useful information (although it may not
seem like it at first!)
> incomevar = (input("Please enter the income: ")
Count the parens, they don;t match up.
You don't need the first opening paren.
> income = int(incomevar)
Indentation is critical in Python. This line being indented
will result in an error.
Also you don;t need two vars there, just overwrite the original:
income = input(...)
income = int(income)
Or in one line:
income = int(input(...))
> costvar = int(input("Please enter the cost: ")
> cost = int(costvar)
See above on indentation.
Plus you don't need the int conversion since you did
that in the line above.
> if income >= cost :
> print (income - cost == profit)
The stuff inside the parens is a boolean expression.
It will evaluate to True or False. So that's what will
get printed, just True or False.
> else income < cost :
else doesn't take an expression it is just plain
else:
# do something here
> I have tried many things for this to work, including changing the variable
> names, spacing issues. Nothing seems to work
"Nothing seems to work" doesn't help us debug the code.
You need to be specific. What doesn't work about it?
- Do you get an error? If so send the error text.
- Does it run but print the wrong thing? If so send the output and
tell us what you expected.
- Does it crash your computer? - that shouldn't really happen often
in Python but in some other languages is surprisingly common!
HTH,
--
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