[Tutor] Help with if-elif-else structure
TheIrda
theirda at gmail.com
Sat Aug 27 13:59:21 CEST 2011
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" <ramit.prasad at jpmorgan.com> 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.com at python.org [mailto:tutor-bounces+ramit.prasad=jpmorgan.com at 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.
More information about the Tutor
mailing list