[Tutor] Help on Python
stephen.m.smith at comcast.net
stephen.m.smith at comcast.net
Tue Oct 15 14:03:23 EDT 2019
I looked at your few lines and made an assumption or two. Pretty sure this
does what you want:
incomevar = input("Please enter the income: ")
income = int(incomevar)
costvar = input("Please enter the cost: ")
cost = int(costvar)
if income >= cost :
print("Profit = ",income - cost)
else:
print ("Loss = ", cost - income)
However, there is some stuff in there you don't need. This works as well and
is a little more efficient and elegant:
income = input("Please enter the income: ")
cost = input("Please enter the cost: ")
result = int(income) - int(cost)
if result > 0:
print("Profit = ",result)
elif result < 0:
print ("Loss = ", result)
else:
print("There was no profit, Income = Expenses!")
Good luck!
-----Original Message-----
From: Tutor <tutor-bounces+stephen.m.smith=comcast.net at python.org> On Behalf
Of David Lowry-Duda
Sent: Tuesday, October 15, 2019 11:45 AM
To: tutor at python.org
Subject: Re: [Tutor] Help on Python
Hello Tyson,
You have found the right email and come to the right place.
> 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.
To get a good response, I suggest you give a bit of additional info. In
particular, I suggest that you add
- what you are trying to do
- what you expect your program to run and do
- the output of your program when it runs (or the error if an error is
produced)
This advice applies not only to this post, but any future questions you
might give to any programming-help environment.
With your post --- with proper indentation, I expect that your program would
not run because `profit` and `loss` are not defined.
Good luck!
- DLD
--
David Lowry-Duda <david at lowryduda.com> <davidlowryduda.com>
_______________________________________________
Tutor maillist - Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list