+ 1

How do we use the iff (if and only if )function

since there is no iff in Python how do we check iff a is divisible by b

7th Nov 2016, 10:21 AM
Siddharth Manghat
Siddharth Manghat - avatar
2 Answers
+ 1
Source: http://www.blendedtechnologies.com/vbs-iif-in-JUMP_LINK__&&__python__&&__JUMP_LINK/18 def iif(condition,resultiftrue,resultiffalse): if condition:return resultiftrue else: return resultiffalse #usage: furrycoat=iif(is_summer==True,”light coat”,”Heavy coat”)
7th Nov 2016, 2:04 PM
Kirk Schafer
Kirk Schafer - avatar
+ 1
Hi, Not sure what you expect your code to do, but I think what you need is if with no else statement, so if a%b ==0: DoStuff() This will do nothing otherwise. >>> def iffy(a,b): ... for i in a: ... if i%b==0: ... print "Well Done!" # you can try with this data: a = range(5) b = 2 iffy(a,b) If you want this to stop as soon as any value of a is not diviible by b, add: else: break
7th Nov 2016, 2:06 PM
Chris
Chris - avatar