Advertisement
fkbullet

Introduction to Programming with Python - Student Query

Oct 12th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. """ Instructions
  2. Write an if statement in the_flying_circus(). It must include:
  3.  
  4. 1.)if, elif, and else statements;
  5. 2.)At least one of and, or, or not;
  6. 3.)A comparator (==, !=, <, <=, >, or >=);
  7. 4.)Finally, the_flying_circus() must return True when evaluated. """
  8.  
  9. """ Solution
  10.  
  11. We can easily gather following four points from the instructions given:
  12.  
  13. 1.)Our solution should have if, elif and else statements.
  14. 2.)It should at least have one of [and, or, not]
  15. 3.)We should use a comparator
  16. 4.)Our function should evaluate to True.
  17.  
  18. Simply just check for two conditions in your conditional statements.
  19. For example:
  20.  
  21. if 3>2 and 3>1:
  22. if x%2 == 0 or x%2 == 1:
  23.  
  24. a more general statement:
  25.  
  26. if True or False:
  27. if True and True:
  28. if False and False:
  29. if not False:
  30.  
  31. Return True in every conditional statement.
  32. For example:
  33.  
  34. if 3>2 and 3>1:
  35.    return True
  36. if x%2 == 0 or x%2 == 1:
  37.    return True
  38.  
  39. if True or False:
  40.    return True
  41. """
  42.  
  43.  
  44. # Make sure that the_flying_circus() returns True
  45.  
  46. def the_flying_circus():
  47.  
  48.     if ________:
  49.         # Don't forget to indent
  50.  
  51.         # the code inside this block!
  52.  
  53.     elif ________:
  54.  
  55.         # Keep going here.
  56.  
  57.         # You'll want to add the else statement, too!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement