Conditoinals!


#1
if not True:
  print True
elif 8 % 3 < 2:
  print False
elif False and True:
  print "None"
else:
  print "Nothing"

Could anyone help me with the answer to this code, please?

And there is something else I want to ask. When I write the code in Python 3 I face some errors! Could you please help me with the right form of this code in Python 3?


#2

Since there are already print statements, then just run it and see what happens…

Python 3

>>> if not True:
  print True
elif 8 % 3 < 2:
  print False
elif False and True:
  print "None"
else:
  print "Nothing"
  
SyntaxError: Missing parentheses in call to 'print'
>>> 

Add the missing parens, and…

>>> if not True:
  print (True)
elif 8 % 3 < 2:
  print (False)
elif False and True:
  print ("None")
else:
  print ("Nothing")

  
Nothing
>>> 

And there is the answer. Now figure how we got here.


#3

Thank you so much I get it!


#4

The author may not have suggested it, but the astute learner will come back to this problem and test all the possible scenarios.

>>> if not False:    # *
  print (True)
elif 8 % 3 < 2:
  print (False)
elif False and True:
  print ("None")
else:
  print ("Nothing")

  
True
>>> 
>>> if not True:
  print (True)
elif 8 % 3 <= 2:    # *
  print (False)
elif False and True:
  print ("None")
else:
  print ("Nothing")

  
False
>>> 
>>> if not True:
  print (True)
elif 8 % 3 < 2:
  print (False)
elif True and True:    # *
  print ("None")
else:
  print ("Nothing")

  
None
>>> 

#5

Thank you , this helped me a lot!


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.