Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35545 > unrolled thread
| Started by | bobflipperdoodle@gmail.com |
|---|---|
| First post | 2012-12-26 15:04 -0800 |
| Last post | 2012-12-26 17:20 -0800 |
| Articles | 17 — 8 participants |
Back to article view | Back to comp.lang.python
Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 15:04 -0800
Re: Please help if you can! Dave Angel <d@davea.name> - 2012-12-26 18:49 -0500
Re: Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 16:04 -0800
Re: Please help if you can! Chris Angelico <rosuav@gmail.com> - 2012-12-27 11:35 +1100
Re: Please help if you can! Joshua Landau <joshua.landau.ws@gmail.com> - 2012-12-27 00:45 +0000
Re: Please help if you can! Mitya Sirenef <msirenef@lightbird.net> - 2012-12-26 19:53 -0500
Re: Please help if you can! Chris Angelico <rosuav@gmail.com> - 2012-12-27 12:00 +1100
Re: Please help if you can! alex23 <wuwei23@gmail.com> - 2012-12-26 22:33 -0800
Re: Please help if you can! Mitya Sirenef <msirenef@lightbird.net> - 2012-12-26 20:17 -0500
Re: Please help if you can! Chris Angelico <rosuav@gmail.com> - 2012-12-27 12:23 +1100
Re: Please help if you can! Mitya Sirenef <msirenef@lightbird.net> - 2012-12-26 20:42 -0500
Re: Please help if you can! Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-12-26 21:45 -0500
Re: Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 16:04 -0800
Re: Please help if you can! Joshua Landau <joshua.landau.ws@gmail.com> - 2012-12-26 23:57 +0000
Re: Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 16:19 -0800
Re: Please help if you can! bobflipperdoodle@gmail.com - 2012-12-26 16:19 -0800
Re: Please help if you can! Dennis <daodennis@gmail.com> - 2012-12-26 17:20 -0800
| From | bobflipperdoodle@gmail.com |
|---|---|
| Date | 2012-12-26 15:04 -0800 |
| Subject | Please help if you can! |
| Message-ID | <7333128a-6866-4e3c-8436-d5b2397beadc@googlegroups.com> |
I really hope you can help!
I need to create a program where the user can order any combination and quantity of 3 products. I then offer a 10% discount if the customer correctly answers a trivia question. After that, there are 3 choices for shipping.
I have most of the program completed but I'm struggling with the most important parts :/ I can get the total with discount to calculate only if i order every item. I also cant figure out how to get the shipping calculated correctly, including where to put any code referring back to the trivia question. Can somebody please help me with this? I would really appreciate it!
Here is the code:
shop_again = 'y'
print("Welcome to the Star Wars Shop!")
customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
while shop_again == 'y':
if (customer == 2):
print("Welcome to the Star Wars Memorabilia Shop!")
customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
elif (customer == 1):
print("Please select an item to update your order and any other number to check out.")
print("Yoda Figure: $10 each.")
print("Star Wars Movie DVD: $20 each.")
print("Death Star Lego Set: $200 each.")
print(" 1 for Yoda Figure")
print(" 2 for Star Wars Movie DVD")
print(" 3 for Death Star Lego Set")
order = eval(input("Order: "))
if (order == 1):
yoda = eval(input("How many Yoda Figures do you want? : "))
yodatotal = 10 * yoda
print("Total:", yodatotal)
print("Current order:", yoda, "for", yodatotal)
if (order == 2):
movie = eval(input("How many Star Wars Movie DVDs do you want? : "))
movietotal = 20 * movie
print("Total:", movietotal)
print("Current order:", movie, "for", movietotal)
if (order == 3):
legos = eval(input("How many Death Star Lego Sets do you want? : "))
legototal = 200 * legos
print("Total:", legototal)
print("Current order:", legos, "for", legototal)
shop_again = input("Would you like to keep shopping? 'Y' for yes, 'N' for no: ")
print()
print("Yoda Figures: ",yoda,"Totaling", yodatotal)
print("Star Wars Movies: ", movie,"Totaling", movietotal)
print("Death Star Legos: ", legos,"Totaling", legototal)
itemstotal = yodatotal + movietotal + legototal
print("Your order before shipping and discounts: ",itemstotal)
print()
print("Answer a trivia question for a discount!")
discount = eval(input("On what planet did Yoda live when Luke Skywalker first met him? 1) Earth 2) Dagobah 3) Pluto :"))
if (discount == 1):
print("Sorry, that answer was wrong!")
if (discount == 2):
print("That's correct, you get a 10% discount!")
if (discount == 3):
print("Sorry, that answer was wrong!")
print()
if (discount == 1):
total = itemstotal
print("Your total before shipping: ",total)
if (discount == 2):
total = itemstotal * .9
print("Your total before shipping: ",total)
if (discount == 3):
total = itemstotal
print("Your total before shipping: ",total)
print("1) Regular Shipping: 3-4 business days, $5.00 per $50 ordered. 2) Express Shipping: overnight, $10 per $50 ordered. 3) Super Saver Shipping: 7-10 business days, free.")
shipping = eval(input("Please select the shipping method you want: "))
if (shipping == 1):
total == total % 50
total == total * 5
print("Your total is: ",total)
if (shipping == 2):
total == total/50
total == total % 50
total == total * 10
print("Your total is: ",total)
if(shipping == 3):
print("Your total is: ",total)
print()
print("Thanks for shopping here! Please come again!")
[toc] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-12-26 18:49 -0500 |
| Message-ID | <mailman.1304.1356565828.29569.python-list@python.org> |
| In reply to | #35545 |
On 12/26/2012 06:04 PM, bobflipperdoodle@gmail.com wrote: > I really hope you can help! > Please use the existing thread when you're continuing to ask the same question. This mailing list has no way to delete messages. So what changes are there between the two versions of the code? Are they marked somehow? Have you absorbed and implemented the very useful comments made by Mitya? Whenever you find yourself doing exactly the same code many times, chances are high that you should factor it into a function, or a class. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | bobflipperdoodle@gmail.com |
|---|---|
| Date | 2012-12-26 16:04 -0800 |
| Message-ID | <e3214f67-f6c3-40e4-9fed-6feadb526fc3@googlegroups.com> |
| In reply to | #35551 |
First, sorry for starting a new post - I didn't want anyone to have to read through the whole first one when the questions were completely different :/ Second, I honestly have no idea how to answer your questions. I am a sophomore in high school and I am trying to learn this on my own because my teacher is not very good at explaining things. i just cant figure out how to get the total when an order is placed without the customer ordering at least one of each item. I also can't figure out how to get the shipping to calculate correctly. It is an intro class and we are using just the basics. Most of what Mitya said is stuff I've never seen before, although I am very grateful for her response, I am supposed to use only what the teacher "taught". Sorry if I frustrated you. I'm just a kid trying to learn. Any help is appreciated On Wednesday, December 26, 2012 6:49:27 PM UTC-5, Dave Angel wrote: > On 12/26/2012 06:04 PM, wrote: > > > I really hope you can help! > > > > > > > Please use the existing thread when you're continuing to ask the same > > question. > > > > This mailing list has no way to delete messages. > > > > So what changes are there between the two versions of the code? Are > > they marked somehow? > > > > Have you absorbed and implemented the very useful comments made by > > Mitya? Whenever you find yourself doing exactly the same code many > > times, chances are high that you should factor it into a function, or a > > class. > > > > > > -- > > > > DaveA
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-12-27 11:35 +1100 |
| Message-ID | <mailman.1308.1356568526.29569.python-list@python.org> |
| In reply to | #35554 |
On Thu, Dec 27, 2012 at 11:04 AM, <bobflipperdoodle@gmail.com> wrote: > Second, I honestly have no idea how to answer your questions. I am a sophomore in high school and I am trying to learn this on my own because my teacher is not very good at explaining things. Unfortunately, there are a great many bad programming courses out there - either because the course material itself is flawed, or because it's being delivered by someone who isn't good at teaching. But fortunately, with Python, you don't need a course at all! Check this out: http://docs.python.org/3/tutorial/index.html You may even be able to work through the tutorial (actually _do_ the examples, btw) in less time than it would take to solve your problem by asking here - it takes time to formulate questions, more time to wait for responses, and then the response may or may not make good sense to you. It's an excellent tutorial; I strongly recommend it to people new to Python, whether they're experienced programmers with other languages or totally new to coding. > i just cant figure out how to get the total when an order is placed without the customer ordering at least one of each item. I also can't figure out how to get the shipping to calculate correctly. It is an intro class and we are using just the basics. Most of what Mitya said is stuff I've never seen before, although I am very grateful for her response, I am supposed to use only what the teacher "taught". > > Sorry if I frustrated you. I'm just a kid trying to learn. Any help is appreciated The rule that you should use only what you've been taught is a restriction, and yes, restrictions may feel annoying. But it actually makes your task easier. Why? Because you have a guarantee (assuming the course material isn't so fundamentally flawed as to make the task impossible) that the goal can be achieved with just those tools. You probably haven't, for instance, been taught about building a dispatch table using a dictionary and a collection of functions, so you don't need to worry about coding that way (as an aside, it's a quite viable way to write something like this). Once you understand the problem AND understand the tools you're working with, it's up to you to figure out how to combine your available tools to solve the problem. That's a fundamental of all programming and, truth to tell, all of life. But it starts with understanding both halves, so to that end I think Mitya's post is quite useful even if the code itself does things you "haven't been taught". You'll just need to do some code massaging at the end. Best of luck in the course. Try not to let it scare you off coding - it's a wonderful world out here, unfathomable powah is unleashed by a few keystrokes! ChrisA import antigravity
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| Date | 2012-12-27 00:45 +0000 |
| Message-ID | <mailman.1309.1356569194.29569.python-list@python.org> |
| In reply to | #35554 |
[Multipart message — attachments visible in raw view] — view raw
On 27 December 2012 00:04, <bobflipperdoodle@gmail.com> wrote: > First, sorry for starting a new post - I didn't want anyone to have to > read through the whole first one when the questions were completely > different :/ > > Second, I honestly have no idea how to answer your questions. I am a > sophomore in high school and I am trying to learn this on my own because my > teacher is not very good at explaining things. > > i just cant figure out how to get the total when an order is placed > without the customer ordering at least one of each item. I also can't > figure out how to get the shipping to calculate correctly. It is an intro > class and we are using just the basics. Most of what Mitya said is stuff > I've never seen before, although I am very grateful for her response, I am > supposed to use only what the teacher "taught". > > Sorry if I frustrated you. I'm just a kid trying to learn. Any help is > appreciated > There's no anger here, by the way. If we were unhappy with you, you'd know ;). But seriously, if we weren't just trying to help, we wouldn't reply. We were just telling you some stuff you needed to know. I'm in school too, and I'm self taught. I also run a little club where I teach people how to code, from scratch. I get where you're coming from, and you should realise you're doing fine. We get a lot of newbies posting on here, and I'm used to seeing code like this. The important part is that your mistakes are small and self-contained. Those are the easy mistakes, and they're the parts that you don't have to worry about. FINALLY: When you use Google Groups, your quotations look to us like this: > This is something I said > > with lots of extra > > lines in the middle > > for no reason. Google > > Groups sucks, basically. So please just delete the part where you quote other people. I think there are other ways of quoting properly, but you might as well just not quote. (When you quoted my post, the result was *literally* twice as long!) Thanks, and good luck.
[toc] | [prev] | [next] | [standalone]
| From | Mitya Sirenef <msirenef@lightbird.net> |
|---|---|
| Date | 2012-12-26 19:53 -0500 |
| Message-ID | <mailman.1310.1356569625.29569.python-list@python.org> |
| In reply to | #35554 |
On 12/26/2012 07:04 PM, bobflipperdoodle@gmail.com wrote:
> First, sorry for starting a new post - I didn't want anyone to have to read through the whole first one when the questions were completely different :/
>
> Second, I honestly have no idea how to answer your questions. I am a sophomore in high school and I am trying to learn this on my own because my teacher is not very good at explaining things.
>
> i just cant figure out how to get the total when an order is placed without the customer ordering at least one of each item. I also can't figure out how to get the shipping to calculate correctly. It is an intro class and we are using just the basics. Most of what Mitya said is stuff I've never seen before, although I am very grateful for her response, I am supposed to use only what the teacher "taught".
I'm sorry to hear that, I just want to clarify - the teacher did not yet
cover
the use of lists, dictionaries and functions?
If that's the case, I have to agree with you that he's probably not a very
good teacher because this task can be done much easier and better
with those 3 concepts, all of which are very easy. If you are barred from
using them, Joshua's post will be most helpful.
If you are curious about the 3 concepts I mentioned, they are covered
in the official python tutorial, but the quick rundown is:
list: a list of items, e.g. a shopping list:
shoplist = ["tea", "cake", "blueberries"]
dictionary: a collection of keys/values, like words/definitions in a
dictionary:
shopping_cart = {"yoda": 3, "dvd": 5} # 3 of yoda figures, 5 dvds
function: a way to group a bunch of code together:
def main():
# do something
# do something else
# la la la
main()
The nice thing about functions is that if you need to repeat
something, let's say, two thousand times, you just call the
function two thousand times, e.g.:
for x in range(2000): main()
Which is much easier than typing in two thousand copies of the same code
(don't ask me how I know!)
- mitya
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-12-27 12:00 +1100 |
| Message-ID | <mailman.1312.1356570059.29569.python-list@python.org> |
| In reply to | #35554 |
On Thu, Dec 27, 2012 at 11:45 AM, Joshua Landau <joshua.landau.ws@gmail.com> wrote: > FINALLY: > When you use Google Groups, your quotations look to us like this: > >> This is something I said >> >> with lots of extra >> >> lines in the middle >> >> for no reason. Google >> >> Groups sucks, basically. > > So please just delete the part where you quote other people. I think there > are other ways of quoting properly, but you might as well just not quote. > (When you quoted my post, the result was *literally* twice as long!) > One of the regulars on the list has posted a run-down of how to post from Google Groups without annoying everyone, and among other things, it recommends manually deleting all the blank lines. To my mind, though, this would be insane and inane tedium. I recommend signing up to the mailing list; see http://mail.python.org/mailman/listinfo/python-list for details. (As an aside, the mailing list is run by Mailman, which is written in Python. So we use Python to discuss Python.) ChrisA
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2012-12-26 22:33 -0800 |
| Message-ID | <190f4692-a7bc-479e-bccd-b96f20bf2e52@uc4g2000pbc.googlegroups.com> |
| In reply to | #35561 |
On 27 Dec, 11:00, Chris Angelico <ros...@gmail.com> wrote: > One of the regulars on the list has posted a run-down of how to post > from Google Groups without annoying everyone, and among other things, > it recommends manually deleting all the blank lines. I'm still posting via Groups and am not seeing my posts come through with blank lines or weird formatting. However, I _am_ regularly (every goddamn day, thanks for nothing, Google) telling the new UI to bugger off and reverting to the old, sane, thread-on-one-page-not-three UI. I think the issues are with the new UI, which just further reinforces my belief that Google are trying to just kill Groups dead.
[toc] | [prev] | [next] | [standalone]
| From | Mitya Sirenef <msirenef@lightbird.net> |
|---|---|
| Date | 2012-12-26 20:17 -0500 |
| Message-ID | <mailman.1314.1356571049.29569.python-list@python.org> |
| In reply to | #35554 |
On 12/26/2012 08:00 PM, Chris Angelico wrote: > On Thu, Dec 27, 2012 at 11:45 AM, Joshua Landau > <joshua.landau.ws@gmail.com> wrote: >> FINALLY: >> When you use Google Groups, your quotations look to us like this: >> >>> This is something I said >>> >>> with lots of extra >>> >>> lines in the middle >>> >>> for no reason. Google >>> >>> Groups sucks, basically. >> So please just delete the part where you quote other people. I think there >> are other ways of quoting properly, but you might as well just not quote. >> (When you quoted my post, the result was *literally* twice as long!) >> > One of the regulars on the list has posted a run-down of how to post > from Google Groups without annoying everyone, and among other things, > it recommends manually deleting all the blank lines. To my mind, > though, this would be insane and inane tedium. I recommend signing up I have to agree - I saw that howto as well and it occurred to me that if we have to delete blank lines manually we might as well use postal pigeons with tiny little papyrus scrolls - at least those don't insert blank lines automatically! -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-12-27 12:23 +1100 |
| Message-ID | <mailman.1316.1356571411.29569.python-list@python.org> |
| In reply to | #35554 |
On Thu, Dec 27, 2012 at 12:17 PM, Mitya Sirenef <msirenef@lightbird.net> wrote: > I have to agree - I saw that howto as well and it occurred to me > that if we have to delete blank lines manually we might > as well use postal pigeons with tiny little papyrus scrolls - > at least those don't insert blank lines automatically! Yes, but they have poor latency, and packet loss due to hawks is a major problem. But an RFC 1149 network is plausible, even if not viable in most situations. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Mitya Sirenef <msirenef@lightbird.net> |
|---|---|
| Date | 2012-12-26 20:42 -0500 |
| Message-ID | <mailman.1317.1356572563.29569.python-list@python.org> |
| In reply to | #35554 |
On 12/26/2012 08:23 PM, Chris Angelico wrote: > On Thu, Dec 27, 2012 at 12:17 PM, Mitya Sirenef <msirenef@lightbird.net> wrote: >> I have to agree - I saw that howto as well and it occurred to me >> that if we have to delete blank lines manually we might >> as well use postal pigeons with tiny little papyrus scrolls - >> at least those don't insert blank lines automatically! > Yes, but they have poor latency, and packet loss due to hawks is a > major problem. But an RFC 1149 network is plausible, even if not > viable in most situations. > > ChrisA I don't know, I played starcraft II by pigeon-net and it worked just fine. Yes, latency is quite bad but it gives you more time to think about strategy... -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-12-26 21:45 -0500 |
| Message-ID | <mailman.1318.1356576350.29569.python-list@python.org> |
| In reply to | #35554 |
On Wed, 26 Dec 2012 20:17:25 -0500, Mitya Sirenef
<msirenef@lightbird.net> declaimed the following in
gmane.comp.python.general:
> I have to agree - I saw that howto as well and it occurred to me
> that if we have to delete blank lines manually we might
> as well use postal pigeons with tiny little papyrus scrolls -
> at least those don't insert blank lines automatically!
>
http://news.google.com/newspapers?nid=2245&dat=19820618&id=2RYzAAAAIBAJ&sjid=XTIHAAAAIBAJ&pg=5615,6417579
A few decades old, but...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | bobflipperdoodle@gmail.com |
|---|---|
| Date | 2012-12-26 16:04 -0800 |
| Message-ID | <mailman.1307.1356567429.29569.python-list@python.org> |
| In reply to | #35551 |
First, sorry for starting a new post - I didn't want anyone to have to read through the whole first one when the questions were completely different :/ Second, I honestly have no idea how to answer your questions. I am a sophomore in high school and I am trying to learn this on my own because my teacher is not very good at explaining things. i just cant figure out how to get the total when an order is placed without the customer ordering at least one of each item. I also can't figure out how to get the shipping to calculate correctly. It is an intro class and we are using just the basics. Most of what Mitya said is stuff I've never seen before, although I am very grateful for her response, I am supposed to use only what the teacher "taught". Sorry if I frustrated you. I'm just a kid trying to learn. Any help is appreciated On Wednesday, December 26, 2012 6:49:27 PM UTC-5, Dave Angel wrote: > On 12/26/2012 06:04 PM, wrote: > > > I really hope you can help! > > > > > > > Please use the existing thread when you're continuing to ask the same > > question. > > > > This mailing list has no way to delete messages. > > > > So what changes are there between the two versions of the code? Are > > they marked somehow? > > > > Have you absorbed and implemented the very useful comments made by > > Mitya? Whenever you find yourself doing exactly the same code many > > times, chances are high that you should factor it into a function, or a > > class. > > > > > > -- > > > > DaveA
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| Date | 2012-12-26 23:57 +0000 |
| Message-ID | <mailman.1305.1356566309.29569.python-list@python.org> |
| In reply to | #35545 |
[Multipart message — attachments visible in raw view] — view raw
THIS IS A LONG POST, BUT IF YOU WANT TO LEARN YOU SHOULD READ IT. SERIOUSLY.
UNLIKE Mitya Sirenef's THIS DOES NOT ASSUME MORE KNOWLEDGE THAN IS IN YOUR
POST ALREADY, ALTHOUGH HIS IS DEFINITELY BETTER OVERALL. AS SUCH, THERE ARE
NO FUNCTIONS.
OK. There are several small errors in here, but there's nothing too large
or worth much worry.
On 26 December 2012 21:40, <bobflipperdoodle@gmail.com> wrote:
> I really hope you can help!
>
> I need to create a program where the user can order any combination and
> quantity of 3 products. I then offer a 10% discount if the customer
> correctly answers a trivia question. After that, there are 3 choices for
> shipping.
>
> I have most of the program completed but I'm struggling with the most
> important parts :/ I get the total of multiple orders of the same item,
> but we can't figure out how to total the entire order - before discounts
> and shipping - and then where to put any code referring back to the trivia
> question. Can somebody please help me with this? I would really appreciate
> it!
>
You write that you "need" to do this, which may hint that this is some sort
of homework. If so, it's generally a nice thing to say as much. That said,
as long as you've given a good shot at it it's normally fine.
> This is the code:
>
My *very first* thought about this code is that it's really badly spaced.
Don't put lines together so much! [https://gist.github.com/4383950] shows
how much nicer things look when they're partitioned more. You may not
agree, but it took about 10 seconds and I prefer it.
> shop_again = 'y'
>
Hold on! Hold on!
shop_again should have a True/False value. It is screaming to be a boolean.
"y" is a letter, not a boolean. Thus:
shop_again = True
This is important because you don't really want to get confused with all
your types. What if shop_again was later changed to be True when a button
was clicked. Why on earth would you set it to "y"? You'd set it to True.
Thus, the sensible option is to have your types right from the very start.
print("Welcome to the Star Wars Shop!")
> customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
>
eval(input(TEXT)) is a *bad* idea.
First of all, eval is really dangerous. Answer "yes" instead and it'll just
crash. Answer True and it'll run... BUT do *neither* the if or the elif!
That's *bad*.
Secondly, you don't need it. Your:
"if(customer == 1)" could be "if(customer == '1')", which would work
without the eval.
And then you've got the standard of "Y/N". So a better question would be:
customer = input("Is there a customer in line? [Y/N]> ")
Finally, you want to accept "Y" *and* "y", so you'd really want:
customer = input("Is there a customer in line? [Y/N]> ").lower()
---------
customer = input("Is there a customer in line? [Y/N]> ").lower()
Because customer really deserves to be boolean [True/False], you'd want to
change it immediately.
customer = (customer == "y")
This second line assumes that all non-"y"s are False, but that's a folly
you'll have to live with for now.
while shop_again == 'y':
>
If you've changed shop_again to be boolean:
while shop_again:
Some people don't get how this line would make sense. But it does. The
"while" statement only cares if it's value it gets is "truthy". Here are
lots of truthy things:
"y" == "y"
True
False == False
not False
"egg loaf"
[1, 2, 1, False, False]
and here are some falsy things:
"n" == "y"
False
True == False
not True
""
[]
If this makes no sense, please just say.
if (customer == 2):
>
Again, if you've done my changes from above:
if not customer:
> print("Welcome to the Star Wars Memorabilia Shop!")
> customer = eval(input("Is there a customer in line? (1 = yes, 2 =
> no)> "))
>
Again:
customer = input("Is there a customer in line? [Y/N]> ").lower()
customer = (customer == "y")
BUT HOLD ON!
Run your program and then answer "2" twice. What happens? It's not good.
The problem is that answering "2" to this second one doesn't skip the loop!
x = ASK
LOOP:
if not x:
ASK
if x:
STUFF
MORE STUFF
Where you want:
x = ASK
LOOP:
if not x:
ASK
if x:
STUFF
MORE STUFF
or (even better):
while not x:
x = ASK
LOOP:
STUFF
MORE STUFF
The second is what I've just decided to call the "ask-until-yes" model.
Basically, you ask until you get a "yes", so you don't have to put the loop
anywhere else. By the time the first loop is over, you *know* that x is
True!
elif (customer == 1):
>
Again, if you've done my changes from above:
elif customer:
> print("Please select an item to update your order and any other
> number to check out.")
> print("Yoda Figure: $10 each.")
> print("Star Wars Movie DVD: $20 each.")
> print("Death Star Lego Set: $200 each.")
> print(" 1 for Yoda Figure")
> print(" 2 for Star Wars Movie DVD")
> print(" 3 for Death Star Lego Set")
> order = eval(input("Order: "))
>
Again:
order = input("Order number: ")
> if (order == 1):
If you've followed my advice:
if order == "1":
> yoda = eval(input("How many Yoda Figures do you want? : "))
total = 10 * yoda
Ooookkay. Now you're thinking: "BUT *surely* I need eval here!!(?)".
You don't.
yoda = int(input("How many Yoda Figures do you want? : "))
This is better because there are so many problems with eval, and int also
means that you can only order whole numbers of yodas.
You probably also want to call this "number_of_yodas", because you're not
defining what "yoda" is.
> print("Total:", total)
print("Current order:", yoda, "at", total)
if (order == 2):
If you've followed my advice:
if order == "2":
> movie = eval(input("How many Star Wars Movie DVDs do you want? :
> "))
total = 20 * movie
As above:
number_of_movies = int(input("How many Star Wars Movie DVDs do you want? :
"))
total = 20 * number_of_movies
print("Total:", total)
print("Current order:", movie, "at", total)
if (order == 3):
If you've followed my advice:
if order == "3":
> legos = eval(input("How many Death Star Lego Sets do you want? :
> "))
total = 200 * legos
As above:
number_of_legos = int(input("How many Death Star Lego Sets do you want? :
"))
total = 20 * number_of_legos
> print("Total:", total)
print("Current order:", legos, "at", total)
> shop_again = input("Would you like to keep shopping? 'Y' for yes, 'N'
> for no: ")
Again:
shop_again = input("Would you like to keep shopping? [Y/N]> ").lower()
shop_again = (shop_again == "y")
> print()
print("Your order before shipping and discounts: ",total)
print()
print("Answer a trivia question for a discount!")
discount = eval(input("On what planet did Yoda live when Luke Skywalker
> first met him? 1) Earth 2) Dagobah 3) Pluto :"))
Again:
discount = input("On what planet did Yoda live when Luke Skywalker first
met him? 1) Earth 2) Dagobah 3) Pluto :")
if (discount == 1):
print("Sorry, that answer was wrong!")
if (discount == 2):
print("That's correct, you get a 10% discount!")
if (discount == 3):
print("Sorry, that answer was wrong!")
If you've taken my advice:
if discount == "1":
print("Sorry, that answer was wrong!")
if discount == "2":
print("That's correct, you get a 10% discount!")
if discount == "3":
print("Sorry, that answer was wrong!")
> print()
if (discount == 2):
If you've taken my advice:
if discount == "2":
> (total * .9)
Hold on! What do you think this line does? What is it meant to do?
You meant:
total = total*.9
Which for clarity should be written:
total = total * 0.9
> print("Your total before shipping: ",total)
print("1) Regular Shipping: 3-4 business days, $5.00 per $50 ordered. 2)
> Express Shipping: overnight, $10 per $50 ordered. 3) Super Saver Shipping:
> 7-10 business days, free.")
shipping = eval(input("Please select the shipping method you want: "))
Again:
shipping = input("Please select the shipping method you want: ")
if (shipping == 1):
If you've taken my advice:
if shipping == "1":
> total == total % 50
total == total * 5
Eeek! Almost!
1) You've mixed up "==" and "=".
Look them up if this was a confusion thing, but I imagine it was
a subconscious typo.
But then what? You've set total to the cost of shipping! What you want is:
shipping = total % 50
shipping = shipping * 5
total = total + shipping
2) %?? You mean "//". Look them up. Now.
"542353 % 50" makes 3!
"542353 // 50" makes 10847, which is what you want.
So:
shipping = total // 50
shipping = shipping * 5
total = total + shipping
print("Your total is: ",total)
if (shipping == 2):
If you've taken my advice:
if shipping == "2":
> total == total/50
total == total % 50
total == total * 10
See above, twice.
> print("Your total is: ",total)
if(shipping == 3):
If you've taken my advice:
if shipping == "3":
> print("Your total is: ",total)
print()
print("Thanks for shopping here! Please come again!")
[toc] | [prev] | [next] | [standalone]
| From | bobflipperdoodle@gmail.com |
|---|---|
| Date | 2012-12-26 16:19 -0800 |
| Message-ID | <65593cba-61e2-4bb0-b47a-2aede8f40577@googlegroups.com> |
| In reply to | #35552 |
I cannot tell you how grateful I am that you took the time to do all of this. I have been working on it all day and you are a better teacher in a few minutes than my teacher has been in 4 months. THANK YOU!
And thank you again, Mitya. I really appreciate your time and effort too! Someday I'll be advanced enough to understand it lol
I'm going to take a break and work on it more tomorrow. I'll be back.
Thank you!
On Wednesday, December 26, 2012 6:57:39 PM UTC-5, Joshua Landau wrote:
> THIS IS A LONG POST, BUT IF YOU WANT TO LEARN YOU SHOULD READ IT. SERIOUSLY.
>
>
> UNLIKE Mitya Sirenef's THIS DOES NOT ASSUME MORE KNOWLEDGE THAN IS IN YOUR POST ALREADY, ALTHOUGH HIS IS DEFINITELY BETTER OVERALL. AS SUCH, THERE ARE NO FUNCTIONS.
>
>
>
> OK. There are several small errors in here, but there's nothing too large or worth much worry.
>
>
>
> On 26 December 2012 21:40, <bobflipp...@gmail.com> wrote:
>
>
> I really hope you can help!
>
> I need to create a program where the user can order any combination and quantity of 3 products. I then offer a 10% discount if the customer correctly answers a trivia question. After that, there are 3 choices for shipping.
>
>
>
> I have most of the program completed but I'm struggling with the most important parts :/ I get the total of multiple orders of the same item, but we can't figure out how to total the entire order - before discounts and shipping - and then where to put any code referring back to the trivia question. Can somebody please help me with this? I would really appreciate it!
>
>
>
>
>
> You write that you "need" to do this, which may hint that this is some sort of homework. If so, it's generally a nice thing to say as much. That said, as long as you've given a good shot at it it's normally fine.
>
>
> This is the code:
>
>
>
>
>
> My *very first* thought about this code is that it's really badly spaced. Don't put lines together so much! [https://gist.github.com/4383950] shows how much nicer things look when they're partitioned more. You may not agree, but it took about 10 seconds and I prefer it.
>
>
> shop_again = 'y'
>
>
>
>
>
> Hold on! Hold on!
> shop_again should have a True/False value. It is screaming to be a boolean. "y" is a letter, not a boolean. Thus:
>
>
> shop_again = True
>
>
>
>
> This is important because you don't really want to get confused with all your types. What if shop_again was later changed to be True when a button was clicked. Why on earth would you set it to "y"? You'd set it to True. Thus, the sensible option is to have your types right from the very start.
>
>
>
> print("Welcome to the Star Wars Shop!")
>
>
> customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
>
>
>
> eval(input(TEXT)) is a *bad* idea.
>
>
> First of all, eval is really dangerous. Answer "yes" instead and it'll just crash. Answer True and it'll run... BUT do *neither* the if or the elif! That's *bad*.
>
>
> Secondly, you don't need it. Your:
>
>
> "if(customer == 1)" could be "if(customer == '1')", which would work without the eval.
>
>
> And then you've got the standard of "Y/N". So a better question would be:
>
>
>
>
> customer = input("Is there a customer in line? [Y/N]> ")
>
>
> Finally, you want to accept "Y" *and* "y", so you'd really want:
>
>
>
>
> customer = input("Is there a customer in line? [Y/N]> ").lower()
>
>
>
> ---------
> customer = input("Is there a customer in line? [Y/N]> ").lower()
>
>
>
> Because customer really deserves to be boolean [True/False], you'd want to change it immediately.
>
>
> customer = (customer == "y")
>
>
> This second line assumes that all non-"y"s are False, but that's a folly you'll have to live with for now.
>
>
>
> while shop_again == 'y':
>
>
>
>
>
> If you've changed shop_again to be boolean:
>
>
> while shop_again:
>
> Some people don't get how this line would make sense. But it does. The "while" statement only cares if it's value it gets is "truthy". Here are lots of truthy things:
>
>
>
>
> "y" == "y"
> True
> False == False
> not False
> "egg loaf"
> [1, 2, 1, False, False]
>
>
> and here are some falsy things:
>
>
>
>
> "n" == "y"
> False
> True == False
> not True
> ""
> []
>
>
> If this makes no sense, please just say.
>
>
>
> if (customer == 2):
>
>
>
>
>
> Again, if you've done my changes from above:
>
>
>
> if not customer:
>
>
> print("Welcome to the Star Wars Memorabilia Shop!")
> customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
>
>
>
> Again:
>
>
>
>
> customer = input("Is there a customer in line? [Y/N]> ").lower()
>
> customer = (customer == "y")
>
>
> BUT HOLD ON!
>
>
> Run your program and then answer "2" twice. What happens? It's not good.
>
>
>
>
> The problem is that answering "2" to this second one doesn't skip the loop!
>
>
> x = ASK
> LOOP:
> if not x:
> ASK
> if x:
>
>
> STUFF
> MORE STUFF
>
>
> Where you want:
>
>
>
> x = ASK
> LOOP:
> if not x:
> ASK
> if x:
> STUFF
>
>
> MORE STUFF
>
>
> or (even better):
>
>
> while not x:
> x = ASK
> LOOP:
> STUFF
> MORE STUFF
>
>
> The second is what I've just decided to call the "ask-until-yes" model. Basically, you ask until you get a "yes", so you don't have to put the loop anywhere else. By the time the first loop is over, you *know* that x is True!
>
>
>
> elif (customer == 1):
>
>
>
>
>
>
> Again, if you've done my changes from above:
>
>
>
> elif customer:
>
>
> print("Please select an item to update your order and any other number to check out.")
> print("Yoda Figure: $10 each.")
> print("Star Wars Movie DVD: $20 each.")
>
>
> print("Death Star Lego Set: $200 each.")
> print(" 1 for Yoda Figure")
> print(" 2 for Star Wars Movie DVD")
> print(" 3 for Death Star Lego Set")
>
>
> order = eval(input("Order: "))
>
>
>
> Again:
>
>
> order = input("Order number: ")
>
>
> if (order == 1):
>
>
> If you've followed my advice:
>
>
> if order == "1":
>
>
> yoda = eval(input("How many Yoda Figures do you want? : "))
>
> total = 10 * yoda
>
>
> Ooookkay. Now you're thinking: "BUT *surely* I need eval here!!(?)".
>
>
> You don't.
>
>
> yoda = int(input("How many Yoda Figures do you want? : "))
>
>
>
>
> This is better because there are so many problems with eval, and int also means that you can only order whole numbers of yodas.
> You probably also want to call this "number_of_yodas", because you're not defining what "yoda" is.
>
>
> print("Total:", total)
>
> print("Current order:", yoda, "at", total)
>
> if (order == 2):
>
>
>
>
>
> If you've followed my advice:
>
>
> if order == "2":
>
>
> movie = eval(input("How many Star Wars Movie DVDs do you want? : "))
>
> total = 20 * movie
>
>
> As above:
>
>
> number_of_movies = int(input("How many Star Wars Movie DVDs do you want? : "))
>
> total = 20 * number_of_movies
>
>
>
> print("Total:", total)
>
> print("Current order:", movie, "at", total)
>
> if (order == 3):
>
>
>
>
>
> If you've followed my advice:
>
>
> if order == "3":
>
>
> legos = eval(input("How many Death Star Lego Sets do you want? : "))
>
> total = 200 * legos
>
>
>
> As above:
>
>
> number_of_legos = int(input("How many Death Star Lego Sets do you want? : "))
>
> total = 20 * number_of_legos
>
>
> print("Total:", total)
>
> print("Current order:", legos, "at", total)
>
>
>
>
> shop_again = input("Would you like to keep shopping? 'Y' for yes, 'N' for no: ")
>
>
> Again:
>
>
> shop_again = input("Would you like to keep shopping? [Y/N]> ").lower()
>
>
>
> shop_again = (shop_again == "y")
>
>
> print()print("Your order before shipping and discounts: ",total)
>
> print()
>
> print("Answer a trivia question for a discount!")
>
> discount = eval(input("On what planet did Yoda live when Luke Skywalker first met him? 1) Earth 2) Dagobah 3) Pluto :"))
>
>
> Again:
>
>
> discount = input("On what planet did Yoda live when Luke Skywalker first met him? 1) Earth 2) Dagobah 3) Pluto :")
>
>
>
> if (discount == 1):
>
> print("Sorry, that answer was wrong!")
>
> if (discount == 2): print("That's correct, you get a 10% discount!")
>
> if (discount == 3):
>
> print("Sorry, that answer was wrong!")
>
>
> If you've taken my advice:
>
>
> if discount == "1":
> print("Sorry, that answer was wrong!")
>
>
> if discount == "2":
> print("That's correct, you get a 10% discount!")
> if discount == "3":
> print("Sorry, that answer was wrong!")
>
>
> print()
>
> if (discount == 2):
>
>
> If you've taken my advice:
>
>
>
> if discount == "2":
>
>
>
> (total * .9)
>
>
> Hold on! What do you think this line does? What is it meant to do?
>
>
> You meant:
>
>
> total = total*.9
>
>
> Which for clarity should be written:
>
>
>
>
> total = total * 0.9
>
>
>
> print("Your total before shipping: ",total)
>
> print("1) Regular Shipping: 3-4 business days, $5.00 per $50 ordered. 2) Express Shipping: overnight, $10 per $50 ordered. 3) Super Saver Shipping: 7-10 business days, free.")
>
> shipping = eval(input("Please select the shipping method you want: "))
>
>
>
>
> Again:
> shipping = input("Please select the shipping method you want: ")
>
>
>
> if (shipping == 1):
>
>
>
> If you've taken my advice:
>
> <br...
> Show original
[toc] | [prev] | [next] | [standalone]
| From | bobflipperdoodle@gmail.com |
|---|---|
| Date | 2012-12-26 16:19 -0800 |
| Message-ID | <mailman.1311.1356570019.29569.python-list@python.org> |
| In reply to | #35552 |
I cannot tell you how grateful I am that you took the time to do all of this. I have been working on it all day and you are a better teacher in a few minutes than my teacher has been in 4 months. THANK YOU!
And thank you again, Mitya. I really appreciate your time and effort too! Someday I'll be advanced enough to understand it lol
I'm going to take a break and work on it more tomorrow. I'll be back.
Thank you!
On Wednesday, December 26, 2012 6:57:39 PM UTC-5, Joshua Landau wrote:
> THIS IS A LONG POST, BUT IF YOU WANT TO LEARN YOU SHOULD READ IT. SERIOUSLY.
>
>
> UNLIKE Mitya Sirenef's THIS DOES NOT ASSUME MORE KNOWLEDGE THAN IS IN YOUR POST ALREADY, ALTHOUGH HIS IS DEFINITELY BETTER OVERALL. AS SUCH, THERE ARE NO FUNCTIONS.
>
>
>
> OK. There are several small errors in here, but there's nothing too large or worth much worry.
>
>
>
> On 26 December 2012 21:40, <bobflipp...@gmail.com> wrote:
>
>
> I really hope you can help!
>
> I need to create a program where the user can order any combination and quantity of 3 products. I then offer a 10% discount if the customer correctly answers a trivia question. After that, there are 3 choices for shipping.
>
>
>
> I have most of the program completed but I'm struggling with the most important parts :/ I get the total of multiple orders of the same item, but we can't figure out how to total the entire order - before discounts and shipping - and then where to put any code referring back to the trivia question. Can somebody please help me with this? I would really appreciate it!
>
>
>
>
>
> You write that you "need" to do this, which may hint that this is some sort of homework. If so, it's generally a nice thing to say as much. That said, as long as you've given a good shot at it it's normally fine.
>
>
> This is the code:
>
>
>
>
>
> My *very first* thought about this code is that it's really badly spaced. Don't put lines together so much! [https://gist.github.com/4383950] shows how much nicer things look when they're partitioned more. You may not agree, but it took about 10 seconds and I prefer it.
>
>
> shop_again = 'y'
>
>
>
>
>
> Hold on! Hold on!
> shop_again should have a True/False value. It is screaming to be a boolean. "y" is a letter, not a boolean. Thus:
>
>
> shop_again = True
>
>
>
>
> This is important because you don't really want to get confused with all your types. What if shop_again was later changed to be True when a button was clicked. Why on earth would you set it to "y"? You'd set it to True. Thus, the sensible option is to have your types right from the very start.
>
>
>
> print("Welcome to the Star Wars Shop!")
>
>
> customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
>
>
>
> eval(input(TEXT)) is a *bad* idea.
>
>
> First of all, eval is really dangerous. Answer "yes" instead and it'll just crash. Answer True and it'll run... BUT do *neither* the if or the elif! That's *bad*.
>
>
> Secondly, you don't need it. Your:
>
>
> "if(customer == 1)" could be "if(customer == '1')", which would work without the eval.
>
>
> And then you've got the standard of "Y/N". So a better question would be:
>
>
>
>
> customer = input("Is there a customer in line? [Y/N]> ")
>
>
> Finally, you want to accept "Y" *and* "y", so you'd really want:
>
>
>
>
> customer = input("Is there a customer in line? [Y/N]> ").lower()
>
>
>
> ---------
> customer = input("Is there a customer in line? [Y/N]> ").lower()
>
>
>
> Because customer really deserves to be boolean [True/False], you'd want to change it immediately.
>
>
> customer = (customer == "y")
>
>
> This second line assumes that all non-"y"s are False, but that's a folly you'll have to live with for now.
>
>
>
> while shop_again == 'y':
>
>
>
>
>
> If you've changed shop_again to be boolean:
>
>
> while shop_again:
>
> Some people don't get how this line would make sense. But it does. The "while" statement only cares if it's value it gets is "truthy". Here are lots of truthy things:
>
>
>
>
> "y" == "y"
> True
> False == False
> not False
> "egg loaf"
> [1, 2, 1, False, False]
>
>
> and here are some falsy things:
>
>
>
>
> "n" == "y"
> False
> True == False
> not True
> ""
> []
>
>
> If this makes no sense, please just say.
>
>
>
> if (customer == 2):
>
>
>
>
>
> Again, if you've done my changes from above:
>
>
>
> if not customer:
>
>
> print("Welcome to the Star Wars Memorabilia Shop!")
> customer = eval(input("Is there a customer in line? (1 = yes, 2 = no)> "))
>
>
>
> Again:
>
>
>
>
> customer = input("Is there a customer in line? [Y/N]> ").lower()
>
> customer = (customer == "y")
>
>
> BUT HOLD ON!
>
>
> Run your program and then answer "2" twice. What happens? It's not good.
>
>
>
>
> The problem is that answering "2" to this second one doesn't skip the loop!
>
>
> x = ASK
> LOOP:
> if not x:
> ASK
> if x:
>
>
> STUFF
> MORE STUFF
>
>
> Where you want:
>
>
>
> x = ASK
> LOOP:
> if not x:
> ASK
> if x:
> STUFF
>
>
> MORE STUFF
>
>
> or (even better):
>
>
> while not x:
> x = ASK
> LOOP:
> STUFF
> MORE STUFF
>
>
> The second is what I've just decided to call the "ask-until-yes" model. Basically, you ask until you get a "yes", so you don't have to put the loop anywhere else. By the time the first loop is over, you *know* that x is True!
>
>
>
> elif (customer == 1):
>
>
>
>
>
>
> Again, if you've done my changes from above:
>
>
>
> elif customer:
>
>
> print("Please select an item to update your order and any other number to check out.")
> print("Yoda Figure: $10 each.")
> print("Star Wars Movie DVD: $20 each.")
>
>
> print("Death Star Lego Set: $200 each.")
> print(" 1 for Yoda Figure")
> print(" 2 for Star Wars Movie DVD")
> print(" 3 for Death Star Lego Set")
>
>
> order = eval(input("Order: "))
>
>
>
> Again:
>
>
> order = input("Order number: ")
>
>
> if (order == 1):
>
>
> If you've followed my advice:
>
>
> if order == "1":
>
>
> yoda = eval(input("How many Yoda Figures do you want? : "))
>
> total = 10 * yoda
>
>
> Ooookkay. Now you're thinking: "BUT *surely* I need eval here!!(?)".
>
>
> You don't.
>
>
> yoda = int(input("How many Yoda Figures do you want? : "))
>
>
>
>
> This is better because there are so many problems with eval, and int also means that you can only order whole numbers of yodas.
> You probably also want to call this "number_of_yodas", because you're not defining what "yoda" is.
>
>
> print("Total:", total)
>
> print("Current order:", yoda, "at", total)
>
> if (order == 2):
>
>
>
>
>
> If you've followed my advice:
>
>
> if order == "2":
>
>
> movie = eval(input("How many Star Wars Movie DVDs do you want? : "))
>
> total = 20 * movie
>
>
> As above:
>
>
> number_of_movies = int(input("How many Star Wars Movie DVDs do you want? : "))
>
> total = 20 * number_of_movies
>
>
>
> print("Total:", total)
>
> print("Current order:", movie, "at", total)
>
> if (order == 3):
>
>
>
>
>
> If you've followed my advice:
>
>
> if order == "3":
>
>
> legos = eval(input("How many Death Star Lego Sets do you want? : "))
>
> total = 200 * legos
>
>
>
> As above:
>
>
> number_of_legos = int(input("How many Death Star Lego Sets do you want? : "))
>
> total = 20 * number_of_legos
>
>
> print("Total:", total)
>
> print("Current order:", legos, "at", total)
>
>
>
>
> shop_again = input("Would you like to keep shopping? 'Y' for yes, 'N' for no: ")
>
>
> Again:
>
>
> shop_again = input("Would you like to keep shopping? [Y/N]> ").lower()
>
>
>
> shop_again = (shop_again == "y")
>
>
> print()print("Your order before shipping and discounts: ",total)
>
> print()
>
> print("Answer a trivia question for a discount!")
>
> discount = eval(input("On what planet did Yoda live when Luke Skywalker first met him? 1) Earth 2) Dagobah 3) Pluto :"))
>
>
> Again:
>
>
> discount = input("On what planet did Yoda live when Luke Skywalker first met him? 1) Earth 2) Dagobah 3) Pluto :")
>
>
>
> if (discount == 1):
>
> print("Sorry, that answer was wrong!")
>
> if (discount == 2): print("That's correct, you get a 10% discount!")
>
> if (discount == 3):
>
> print("Sorry, that answer was wrong!")
>
>
> If you've taken my advice:
>
>
> if discount == "1":
> print("Sorry, that answer was wrong!")
>
>
> if discount == "2":
> print("That's correct, you get a 10% discount!")
> if discount == "3":
> print("Sorry, that answer was wrong!")
>
>
> print()
>
> if (discount == 2):
>
>
> If you've taken my advice:
>
>
>
> if discount == "2":
>
>
>
> (total * .9)
>
>
> Hold on! What do you think this line does? What is it meant to do?
>
>
> You meant:
>
>
> total = total*.9
>
>
> Which for clarity should be written:
>
>
>
>
> total = total * 0.9
>
>
>
> print("Your total before shipping: ",total)
>
> print("1) Regular Shipping: 3-4 business days, $5.00 per $50 ordered. 2) Express Shipping: overnight, $10 per $50 ordered. 3) Super Saver Shipping: 7-10 business days, free.")
>
> shipping = eval(input("Please select the shipping method you want: "))
>
>
>
>
> Again:
> shipping = input("Please select the shipping method you want: ")
>
>
>
> if (shipping == 1):
>
>
>
> If you've taken my advice:
>
> <br...
> Show original
[toc] | [prev] | [next] | [standalone]
| From | Dennis <daodennis@gmail.com> |
|---|---|
| Date | 2012-12-26 17:20 -0800 |
| Message-ID | <mailman.1315.1356571249.29569.python-list@python.org> |
| In reply to | #35545 |
[Multipart message — attachments visible in raw view] — view raw
> > My *very first* thought about this code is that it's really badly spaced. > Don't put lines together so much! [https://gist.github.com/4383950] shows > how much nicer things look when they're partitioned more. You may not > agree, but it took about 10 seconds and I prefer it. > > On another style note, you may want to take a look at this thread: http://stackoverflow.com/questions/5611776/what-are-the-comprehensive-lint-checkers-for-python Keeping your code style consistent and readable is a fundamental tenant of Python development. That link specifically points out PEP8: http://www.python.org/dev/peps/pep-0008/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web