Re: [Tutor] Query String
On 19/02/13 07:30, Sunil Tech wrote: Here i request, can you tell me what is Query String with some examples? It depends on the context but I suspect you mean in the context of a web app? In that case a query string is the bit at the end of a URL that includes the search parameters etc. Thus if I do a search on Google for query string the url used is: https://www.google.co.uk/#hl=ensugexp=les%3Bgs_rn=3gs_ri=psy- abtok=XeR8I7yoZ93k_zpsfFWQegcp=8gs_id=i7xhr=tq=query+string es_nrs=truepf=ptbo=dbiw=1375bih=897sclient=psy-aboq=query+st gs_l=pbx=1bav=on.2,or.r_gc.r_pw.r_cp.r_qf.bvm=bv.42553238,d.d2k fp=e58955d3a8f3f3a1 And everything after the uk/ is the query string. That particular search brings back lots of links about query strings. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Query String
Thank you Alan. On Tue, Feb 19, 2013 at 2:44 PM, Alan Gauld alan.ga...@btinternet.comwrote: On 19/02/13 07:30, Sunil Tech wrote: Here i request, can you tell me what is Query String with some examples? It depends on the context but I suspect you mean in the context of a web app? In that case a query string is the bit at the end of a URL that includes the search parameters etc. Thus if I do a search on Google for query string the url used is: https://www.google.co.uk/#hl=**ensugexp=les%3Bgs_rn=3gs_**ri=psy-https://www.google.co.uk/#hl=ensugexp=les%3Bgs_rn=3gs_ri=psy- abtok=XeR8I7yoZ93k_zpsfFWQeg**cp=8gs_id=i7xhr=tq=query+**string es_nrs=truepf=ptbo=dbiw=**1375bih=897sclient=psy-ab**oq=query+st gs_l=pbx=1bav=on.2,or.r_gc.**r_pw.r_cp.r_qf.bvm=bv.**42553238,d.d2k fp=e58955d3a8f3f3a1 And everything after the uk/ is the query string. That particular search brings back lots of links about query strings. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ __**_ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Query String
On Tue, Feb 19, 2013 at 4:14 AM, Alan Gauld alan.ga...@btinternet.com wrote: https://www.google.co.uk/#hl=en Just to clarify, using a fragment (#) like that isn't a standard query. It's a JavaScript trick for manipulating browser history based on location.hash, so one can do AJAX page refreshes without breaking the back button. You can see the actual query URL ('.../search?hl=en') if you view the background GET (e.g. in the Firefox web console). urlparse.urlsplit parses 'hl=en' as the fragment in this case: urlparse.urlsplit('https://www.google.co.uk/#hl=en') SplitResult(scheme='https', netloc='www.google.co.uk', path='/', query='', fragment='hl=en') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On 19/02/2013 02:15, Steven D'Aprano wrote:hon modules. Many people will advise that learning C is a good idea. I understand their arguments, but as an old curmudgeon I can say I don't like C and I think the world would be much better without it :-) Does this comment extend to C++? :-) Could the experts, please, recommend a beginner's book to learn the principles of good programming? Ta muchly, Sydney -- Professor Sydney Shall, Department of Haematological Medicine, King's College London, Medical School, 123 Coldharbour Lane, LONDON SE5 9NU, Tel Fax: +44 (0)207 848 5902, E-Mail: sydney.shall, [correspondents outside the College should add; @kcl.ac.uk] www.kcl.ac.uk ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] help with storing money variable
Hi guys, Iam halfway through my vending machine program that I started earlier. I ran into a problem. When the user inserts some money, The money variable is not stored for until the user buys an item. So what happens is when the users inserts some coins and then trys to buy an item the money they inserted is not stored till they buy item.Can you tell me how this can be overcome, so that when the user trys to buy an item,the vending machine correctly looks at the amount of money they have and vends the item depending on the amound of money they have. Here is the code: def printMenu(): print (|__|) print (|Menu: |) print (|--|) print (| 1. Display all Items|) print (| 2. Insert 10p |) print (| 3. Insert 20p |) print (| 4. Insert 50p |) print (| 5. Insert £1|) print (| 6. Buy an item |) print (| 7. Print Current Amount |) print (| 8. Exit |) print (|__|) while True: printMenu() choice = input(enter an option from the menu: ) if choice == '1': print() print( A BC) print( 1.[ Vimtos ] [ Chewits ] [ Mars Bar ]) print([ 50p ] [ 40p] [ 50p ]) print() print( 2.[ Doritos ] [ Mentos ]) print([ 60p] [ 50p ]) print() elif choice == '2': money = 0 number = int(input(how many 10p: )) money += number * 1/10 print(your newly updated credit is £ + str(money) + 0) elif choice == '3': money = 0 number2 = int(input(how many 20p: )) money += number2 * 2/10 print(your newly updated credit is £ + str(money) + 0) elif choice == '4': money = 0 number3 = int(input(how many 50p: )) money += number3 * 5/10 print(your newly updated credit is £ + str(money) + 0) elif choice == '5': money = 0 number4 = int(input(how many £1: )) money += number4 * 1 print(your newly updated credit is £ + str(money)) elif choice == '6': code = input(Enter the code of item you want to buy e.g. for Vimtos = a1: ) money = 0 pricea1 = 0.50 pricea2 = 0.60 priceb1 = 0.40 priceb2 = 0.50 pricec1 = 0.50 if code == 'a1': if money pricea1: print(you have bought a packet of Vimtos and your newly updated balance is + str(money - pricea1)) money -= pricea1 else: print(you can't buy that item as your credit is too low) if code == 'a2': if money pricea2: print(you have bought a packet of Doritos and your newly updated balance is + str(money - pricea2)) money -= pricea2 else: print(you can't buy that item as your credit is too low) if code == 'b1': if money priceb1: print(you have bought a packet of Chewits and your newly updated balance is + str(money - priceb1)) money -= priceb1 else: print(you can't buy that item as your credit is too low) if code == 'b2': if money priceb2: print(you have bought a packet of Mentos and your newly updated balance is + str(money - pricea2)) money -= priceb2 else: print(you can't buy that item as your credit is too low) if code == 'c1': if money pricec1: print(you have bought a Mars Bar and your newly updated balance is + str(money - pricea2)) money -= priceb2 else: print(you can't buy that item as your credit is too low) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help with storing money variable
On 02/19/2013 07:36 AM, Ghadir Ghasemi wrote: Hi guys, Iam halfway through my vending machine program that I started earlier. I ran into a problem. When the user inserts some money, The money variable is not stored for until the user buys an item. So what happens is when the users inserts some coins and then trys to buy an item the money they inserted is not stored till they buy item.Can you tell me how this can be overcome, so that when the user trys to buy an item,the vending machine correctly looks at the amount of money they have and vends the item depending on the amound of money they have. Here is the code: def printMenu(): print (|__|) print (|Menu: |) print (|--|) print (| 1. Display all Items|) print (| 2. Insert 10p |) print (| 3. Insert 20p |) print (| 4. Insert 50p |) print (| 5. Insert £1|) print (| 6. Buy an item |) print (| 7. Print Current Amount |) print (| 8. Exit |) print (|__|) while True: printMenu() choice = input(enter an option from the menu: ) if choice == '1': print() print( A BC) print( 1.[ Vimtos ] [ Chewits ] [ Mars Bar ]) print([ 50p ] [ 40p] [ 50p ]) print() print( 2.[ Doritos ] [ Mentos ]) print([ 60p] [ 50p ]) print() elif choice == '2': money = 0 number = int(input(how many 10p: )) money += number * 1/10 print(your newly updated credit is £ + str(money) + 0) elif choice == '3': money = 0 number2 = int(input(how many 20p: )) money += number2 * 2/10 print(your newly updated credit is £ + str(money) + 0) elif choice == '4': money = 0 number3 = int(input(how many 50p: )) money += number3 * 5/10 print(your newly updated credit is £ + str(money) + 0) elif choice == '5': money = 0 number4 = int(input(how many £1: )) money += number4 * 1 print(your newly updated credit is £ + str(money)) elif choice == '6': code = input(Enter the code of item you want to buy e.g. for Vimtos = a1: ) money = 0 pricea1 = 0.50 pricea2 = 0.60 priceb1 = 0.40 priceb2 = 0.50 pricec1 = 0.50 if code == 'a1': if money pricea1: print(you have bought a packet of Vimtos and your newly updated balance is + str(money - pricea1)) money -= pricea1 else: print(you can't buy that item as your credit is too low) if code == 'a2': if money pricea2: print(you have bought a packet of Doritos and your newly updated balance is + str(money - pricea2)) money -= pricea2 else: print(you can't buy that item as your credit is too low) if code == 'b1': if money priceb1: print(you have bought a packet of Chewits and your newly updated balance is + str(money - priceb1)) money -= priceb1 else: print(you can't buy that item as your credit is too low) if code == 'b2': if money priceb2: print(you have bought a packet of Mentos and your newly updated balance is + str(money - pricea2)) money -= priceb2 else: print(you can't buy that item as your credit is too low) if code == 'c1': if money pricec1: print(you have bought a Mars Bar and your newly updated balance is + str(money - pricea2)) money -= priceb2 else: print(you can't buy that item as your credit is too low) How did you conclude that the money they deposit isn't stored till they try to buy something? Are you really saying it isn't visible to the user? Could it be because you forgot the elif code == 7 case? (And the 8 one as well.) The other problem I see is that many of those choices zero the value bound to money. That should be zeroed before the while loop, not inside any place somebody deposits something. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
Could the experts, please, recommend a beginner's book to learn the principles of good programming? I don't know about expert, but I found the Head First Lab's approach to be really good. The Python book is structured like so: -Lists introduction -(PyPi)/creating modules -- this I hope has been changed in future editions of the book, because PyPi now has a test server for those learning to use it, instead of people uploading to the official PyPi server (if you've ever wondered why there are so many modules for printing lists within lists (nester.py)). -Error handling -Saving data -Work on data -OOP -Web development -Mobile App development -Handling input -Scaling your webapp (which you built in the web development chapter) -Handling complexity Each chapter consists of a challenge that you'll work; the work on data one has a Coach Kelly giving you his files on runner times, wanting it formatted. So first you'll learn to read it in, sanitize it and everything, and after that you move on to OOP design, where you create a new class (let's see if I recall it): class Athlete: def __init__(self, name, dob=None, times=[]): self.name = name self.dob = dob self.times = times def add_time(self, time): self.times.append(time) def add_times(self, times): self.times.extend(times) After you've designed the class yourself they go on to mention that instead of building functionality that already exists -- self.times.extend(times) -- it's probably better to create a class that inherits from list, like so: class AthleteList(list): def __init__(self, name, dob=None, times=[]): list.__init__([]) self.name = name self.dob = dob self.extend(times) In each chapter they go through various approaches on things that crop up; for error handling it's the add extra logic/ask forgiveness, for classes it's custom class or inherited class, for saving data it's custom code vs off the shelf solutions, why you want to create functions instead of duplicate code and so on. It's well structured, readable, and have quite enjoyable challenges (compared to the usual Hello World approach that many other books do). So yes, they teach you Python, but they also teach you the principles of good programming. I recommend it to anyone who wants to learn Python, but there are probably better books for *specifically* programming principles -- this book is more of a bundled deal. -- best regards, Robert S. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Query String
On 19/02/13 11:35, eryksun wrote: On Tue, Feb 19, 2013 at 4:14 AM, Alan Gauld alan.ga...@btinternet.com wrote: https://www.google.co.uk/#hl=en Just to clarify, using a fragment (#) like that isn't a standard query. Yes I noticed the anomaly but I chose that particular query for a reason :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] help with storing money variable
On 19/02/13 12:36, Ghadir Ghasemi wrote: def printMenu(): print (|__|) print (| 2. Insert 10p |) print (| 3. Insert 20p |) print (| 4. Insert 50p |) print (|__|) while True: elif choice == '2': money = 0 number = int(input(how many 10p: )) money += number * 1/10 elif choice == '3': money = 0 number2 = int(input(how many 20p: )) money += number2 * 2/10 elif choice == '4': money = 0 number3 = int(input(how many 50p: )) money += number3 * 5/10 In each case you start by zeroing money thus losing any credit they had built up. If a real machine did that to me I'd me mighty annoyed. Just a thought... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
On 19/02/13 11:27, Shall, Sydney wrote: Could the experts, please, recommend a beginner's book to learn the principles of good programming? Thats exactly what my book tries to do although it focuses on Python. But its really more about the general principles than learning the idioms of the language. The bad news is that it's now 12 years old and the language has moved on, although most (all?) of the code will still work in Python 2.7. Should be available through your local library or cheap on Amazon marketplace... The good news is that an updated and extended version is on the web (see the.sig) and is free! :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] following on
Does this comment extend to C++? :-) Could the experts, please, recommend a beginner's book to learn the principles of good programming? I'm partial to How to Design Programs as a beginner's textbook: http://www.ccs.neu.edu/home/matthias/HtDP2e/ because it emphasizes a systematic approach to designing programs. Basically, it's a Polya's How to Solve It for programmers, with an expanded treatment on how data structures inform the shape of the functions that work on that data. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor