CS1011 Unit 3 Sample Solution
A sample solution: Describe the difference between a chained conditional and a nested conditional. Give your own example of each. Both chained and nested conditionals can be used to test when there are two or more possibilities to test in a programming logic. The first of these – chained conditional – is in a condition where exactly one branches (one of the alternative logic paths) will run within the condition body (Downey, 2015). In the coding example below, if I pass in an gender and an age argument in to the genderAndStatus1 function, only one of the five possible branches will be evaluated based on what I pass in for gender and age arguments, and each branch condition is checked one by one, until one of the branch evaluations becomes true. >>> def genderAndStatus1(gender, age): if gender == 'male' and age >=18: print("Male Adult") elif gender == 'male' and age <18: print("Male Minor") elif gender == 'female'