Re: [Tutor] methods vs. functions
Well, my understanding is that function are used in procedural programmming to make the code reusable, and to divide the bigger problem in a serie of smaller ones. Methods are used in OOP, and mainly are the actions taht objects can perform. Thay have a very similar syntax in python, but the concept is quite different. In the procedural programming you have the code that manipulare date to get the result, while in OOP you have objects that act through methods to get teh result. At least this is my understanding :) 2011/8/22 Prasad, Ramit > Steven D'Aprano wrote: > >(Methods are very similar to functions. At the most basic level, we can > >pretend that a method is just a function that comes stuck to something > >else. Don't worry about methods for now.) > > Can someone please explain the difference between methods and functions? > > Thanks, > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://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] Help with if-elif-else structure
Hello, I'm quite new on python, so don't hit too hard if I'm wrong ;) A question on the logic... Does this means if roll[0] > 15: if roll[1] >= 2: print("Success") elif roll[2] >= 2: print("Critical failure!") that rolling multiple 1's get the priority on rolling multiple 6's? I mean result > 15 and 2 1's is always a critical success even if multiple 6 are rolled? also if roll[0] > 15: . elif roll[0] <=15: <--- this is redundant. already checked for > 15 so if here is always <= 15 if roll[1] >= 2: you can change with: elif roll[1] >= 2: And... which is the RPG name ? :p Cheers ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with if-elif-else structure
let me rephrase. They code say: If roll[0] >15 : .. elif roll[0] <= 15: If the code arrive to the elif, it is for sure <= 15. Cheers. Inviato da iPhone Il giorno 26/ago/2011, alle ore 17:21, "Prasad, Ramit" ha scritto: >> if roll[0] > 15: >>. >> elif roll[0] <=15: <--- this is redundant. already checked for > 15 so if >> here is always <= 15 >> if roll[1] >= 2: >> >> you can change with: >> >> elif roll[1] >= 2: > > That is not true. The first one looks at index [0], while the second one is > index[1]. > >>> if roll[0] > 15: >>> if roll[1] >= 2: >>> print("Success") >>> elif roll[2] >= 2: >>> print("Critical failure!") > > This will print "Success" if the first roll is greater than 15 AND second > roll is 2 or greater. > > It will print "Critical failure!" if the first roll is greater than 15 AND > the second roll is less than 2 AND the third roll is 2 or greater. > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > > From: tutor-bounces+ramit.prasad=jpmorgan@python.org > [mailto:tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of > TheIrda > Sent: Friday, August 26, 2011 8:55 AM > To: Christopher King > Cc: python mail list > Subject: Re: [Tutor] Help with if-elif-else structure > > Hello, > > I'm quite new on python, so don't hit too hard if I'm wrong ;) > > > A question on the logic... Does this means > > if roll[0] > 15: >if roll[1] >= 2: >print("Success") >elif roll[2] >= 2: >print("Critical failure!") > > > that rolling multiple 1's get the priority on rolling multiple 6's? I mean > result > 15 and 2 1's is always a critical success even if multiple 6 are > rolled? > > also > > if roll[0] > 15: >. > elif roll[0] <=15: <--- this is redundant. already checked for > 15 so if > here is always <= 15 > if roll[1] >= 2: > > you can change with: > > elif roll[1] >= 2: > > > > And... which is the RPG name ? :p > Cheers > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor