[FRPythoneers] Hi All...
foo7775 at comcast.net
foo7775 at comcast.net
Thu Jan 5 19:18:22 MST 2017
Hello everyone, & happy 2017.
I'm a n00b to this list, & also to Python, although I'm reasonably comfortable with shell scripting in bash, & I've played around a *little* bit with Perl. I'm currently working my way through a Kindle e-book on Python, & I've smacked my head into an issue that (so far, at least) I haven't been able to reason my way out of. The original "assignment" was to prompt the user for:
an original price for an item,
a discount percentage,
and then to calculate the total price for the item once the discount (+ a static sales tax percentage) was factored in.
I took a couple of runs at how to lay out the math, but came up with the following fairly quickly, which seems to work:
TAX = 8.5
initial = int(input("Please enter the item's price: "))
disc = int(input("Please enter any applicable discount "))
print ("Item price is ", initial ) # The 'initial' variable is proven to be working correctly here
print ("The discount is ", disc '%') # Same for the 'disc' variable
price = (initial * ((100 - disc) / 100) * (1 + (TAX / 100)))
print ("Total price is ", price )
Now the overall program (as shown above) basically works as I expected/intended. I can enter an "original price", enter a discount percentage, & get a "total price" that is consistent with the value that I receive when I perform the same process with a calculator. The issue is (essentially) one of formatting. In the second print line (the one containing the 'disc' variable), what I *want* to do is to include a literal 'percent sign' character (i.e., '%') in the output - but regardless of how I try to quote or escape that character, I have yet to hit upon the arcane combination that allows me to see the string
The discount is 20% (or whatever 'disc' value I enter)
in the output.
I have worked my way through several web pages that attempt to explain the function of the % character, from the "somewhat arcane"...
to the entertaining & informative...
but none have provided the "Ah-ha!" moment that I've hoped for.
I will happily admit that I've only barely gotten started with Python, so the example shown in the 'stackoverflow.com' link above could be entirely valid - but it's also essentially incomprehensible to me, so I need to ask - is what I'm trying to do *possible* for me at my level of expertise, or should I just "settle for" using a string like 'pct.' or 'percent' until I understand the 'stackoverflow.com' page??? (Personal note - I'm fairly bullheaded/determined, so if there's ANY way to avoid it, I am *NOT* going to accept a workaround if I don't have to...)
Thank you in advance, I truly appreciate any efforts to "clear this up" for me.
(FWIW, I have a text file that shows the output of different things that I've tried, but I don't yet have any idea whether or not it's appropriate/accepted to include attachments to this list. I am *more* than happy to share it with anyone who's interested in looking at it. Thanks again.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the FRPythoneers