Professional Documents
Culture Documents
CS 1101 - AY2022-T2 - Discussion Unit 3
CS 1101 - AY2022-T2 - Discussion Unit 3
CS 1101 - AY2022-T2 - Discussion Unit 3
Search forums
The cut-off date for posting to this forum is reached so you can no longer post to it.
Discussion Unit 3
by Leonidas Papoulakis (Instructor) - Wednesday, 10 November 2021, 7:09 AM
Describe the difference between a chained conditional and a nested conditional. Give your own example of each. Do not copy
examples from the textbook.
Deeply nested conditionals can become difficult to read. Describe a strategy for avoiding nested conditionals. Give your own
example of a nested conditional that can be modified to become a single conditional, and show the equivalent single
conditional. Do not copy the example from the textbook.
70 words
Permalink
Unit 3 Discussion
In chained conditionals, the conditional statement(if) and the alternate execution or branches (elif/else) are indented on the
same depth meaning they are separate blocks of codes While nested conditional statements are conditional statements where
other conditional statements are put within another conditional statement by using indentation.
test=10
exam=40
if test+exam>=70:
print('You passed with distinction')
elif test+exam>=40<=69:
print('You passed with C')
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 1/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
else:
print('You failed, try harder next time')
#The above code gave the elif condition as output.
test=40
exam=40
if test+exam>=80:
if test+exam<=90:
print('You passed with A-')
#The two nested conditional statements can be put in a single line .
test=40
exam=40
if test+exam>=80 <=90:
print('You passed with A-')
181 words
Hi stephen, clear and concise discussion. Great that you kept the same example for both sections of the discussion. Keep it
up!
22 words
Nice and concise explanation of chained and nested conditionals. Great use of different colours to make the comments
stand out. You covered all the necessary criteria. Keep up the good work.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 2/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
31 words
very simple and easy to understand! also the colors help make it easier to read
15 words
Your input into the discussion is clear. Thank you for your input. Your explanation for the different type of conditions is
quite clear. The examples you gave for the codes are equally good.
33 words
Hello Stephen,
The explanation of the difference between nested and chained conditionals was easy to understand. Moreover, using the
same code to spot on the differences between them was great. well done!!
32 words
Hi well done. keep up the great job. You explain very well.
12 words
Hi Stephen
Good work. well demonstrated idea
7 words
A chained conditional is linear in nature. From the top to the bottom there are a series of individual conditions which are
evaluated one after the other as can be seen below:
fingers = 10
If one condition in the series evaluates to true, the statement inside the condition is executed and the conditions below it are
discarded.
In the case of nested conditions we can think of the structure as a tree. When we nest conditions we are making branch like
structures. Starting from the base of the trunk the program goes to where there is the first split in the trunk. If the first
condition is true the program will continue to evaluate the further branches or conditions nested within the first branch. If
none of those conditions are true it will move on to the next main branch, for example:
dadsAge = 56
if dadsAge > 60: #statement evaluates to false so the nested condition will be skipped
print(“dad is old”)
if dadsAge == 65:
if dadsAge < 60: # this condition evaluates to true and so continues to check the nested condition
if dadsAge == 56: # this condition is also true and the statement will be executed
Deeply nested conditions can be avoided by using the operators “and” and “or” to check multiple criteria in one single
condition. We can use the following example to demonstrate this like so:
# nested condition
val = 0.5
if (type(val) == float):
print("success")
# single condition
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 4/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
print(“success”)
Nice explanation, you answer the question straight to the core, but would better if you cite the sources next time.nkeep
learning bro.
22 words
Great discussion. Your analogies are on point and even cleared up a few doubts I Still had. I always look forward in going
over your discussion. You have a great strenght in this subject. Keep it up!
37 words
Hi, Luke, your explanation is very nice overall. I have learned from you how to avoid nested conditions and that is great.
The examples you give are also clear and detailed.
31 words
Integrating the "type" command for your example enlightened my knowledge. All of your explanations are clear and
helpful. Thank you for the posting!
23 words
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 5/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Hey Luke,
I see you went in dept in expressing the difference both. A job well done.
17 words
Give your own example of each. Do not copy examples from the textbook.
avoiding nested conditionals. Give your own example of a nested conditional that
can be modified to become a single conditional, and show the equivalent single
Answer: The basic difference between chained conditionals, and nested conditionals, stands
on the fact that chained conditionals don't separate commands in only two different
branches, but even more, and it does so by using the function "elif", which is the
abbreviation of "else if". Nested conditionals, on the other hand, are conditionals
found within the statements, and they create branches within branches, thus
making it challenging to quickly read more complex coding (Downey A., 2015).
Chained conditional
a = 15
if 10 < a < 20 :
else:
print("Out of bounds")
>>> or
a = 3
if 10 < a < 20 :
else:
print("Out of bounds")
Out of bounds
a = 22
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 6/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
if 10 < a < 20 :
else:
if 21 < a < 30 :
else:
print("Out of bounds")
>>> or
a = 17
if 10 < a < 20 :
else:
if 21 < a < 30 :
else:
print("Out of bounds")
>>> As you can already see, this very simple code already embraces the reversibility of
strategy to avoid using nested conditionals, it's just a matter of attention. Both
types of conditionals can have the same exact purpose, the main difference is that
nested conditionals can make a more complex code far more clumsy and difficult
Reference
nd Edition. This book is licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0).
400 words
Good job in your discussion. I like the fact that you can use relevant examples that helps to further understand the current
subject. Keep it up!
26 words
You explained chained and nested conditionals correctly. Good that you pointed out that elif stands for elseif, which may
not be apparent to everybody. You used references, but be careful when copying and pasting the source reference as you
included the creative commons license which is not necessary.
48 words
Re: Discussion Unit 3
by Stephen Chuks - Monday, 29 November 2021, 3:03 AM
Your explanations are good. You noted some very important points but your code was not clear because of lack of
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 7/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
indentation. It's understandable though - pasting your codes on this comment box rearranged the code but this post is
strictly about the use of nesting and indentation so it's particularly important that you should try show the indentation.
Overall, you did good.
62 words
Hi, Leameo, your explanation is good overall. You have explained the difference between chained and nested conditionals
clear. But I have noticed that you explained there is no way of avoiding nested conditionals. As our classmate, Luke
explained there is a way to avoid that problem and you can learn from his writings as I did.
56 words
Thanks to everybody, I appreciate your comments on my work atleast I can use it to improve next time. I hope after
school shall have closed, we all can work on a project together.
34 words
Hi Leamao
Discussion – Unit 3
The term chained condition refers to setting conditions that are of the same level in python. The level of indenting of all the if,
elif and else condition is the same. This means their execution is more or less in the same level of comparison for in all
conditions. There is basically no condition within the first condition.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 8/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Nested condition refers to a condition that has more than one level. The if , elif and else conditions are of different levels. A
condition is placed within another condition and therefore if first condition is not met then execution of the condition is
skipped and the next condition is executed. We normally indent the sub-conditions in a different position in python.
Deeply nested conditionals can become difficult to read. Describe a strategy for avoiding nested conditionals. Give your own
example of a nested conditional that can be modified to become a single conditional, and show the equivalent single conditional.
The best strategy to avoid nested condition based on the examples below is to reduce the number of conditions in an
argument. Compiling the major arguments in may reduce the number of conditions one is using and therefore help to avoid a
nested condition. Look at the example below:
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 9/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
The condition has two levels the first level checks if the test has been approved, if True the program will go ahead and execute
the fist if condition with all its sub-conditions. If the first condition is not met , the else condition is executed.
I have reduced the conditions in the nested condition above and below are the results of a the program with chained
condition.
Reference
Downey, A. (2015). Think Python: How to Think Like a Computer Scientist (2nd ed.). Green Tea
Press
Khan Academy (2021, January 1). Nested conditionals (if/else/if) | AP CSP (article).
https://www.khanacademy.org/computing/ap-computer-science-principles/programming-101/boolean-logic/a/nested-
conditionals
Kodify.Net(2019). Python’s nested if statements: if code inside another if statement. Kodify.Net. https://kodify.net/python/if-
else/nested-if/
332 words
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 10/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Nice explanation of chained and nested conditions. Resources clearly presented and in accordance with the APA format.
Make sure to double check your work for spelling mistakes. Nice use of pictures but please make sure to zoom in or
increase the size of the text in your IDE as it is a little hard to read. Overall good work.
59 words
Great work you have there. Your explanations are straight and concise. and your coding is creative.
16 words
Hi, Simon, very nice explanation as well as the examples. You have also provided helpful references with APA standards. I
have learned a lot from you. thank you.
28 words
Nice explanations, just that the codes written in your editor are little harder to read, please improve the readibility of your
codes next time.
24 words
This is a great posting with creativity and detailed explanations. Ultimately, I've learned from your posting what I wanted
to do but was not able to make it happen for my examples and that was grafting function into conditionals. I was kept
trying to use the "print" command to get the outcome and did not work out, but now I have a better understanding of
both last week's and this week's learning materials. Thank you for the posting.
78 words
the answer looks clean and well explained, but the pictures could have been bigger .
15 words
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 11/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Hey Simon, this is incredible. You pointed out the difference well. I also find one of your references helpful, thanks for
sharing, and keep the great work in learning to program.
31 words
Great job in your discussion. You explain the difference between chained and nested condition very well.
16 words
The difference between nested conditionals and chained conditionals is that in the chained conditionals when the condition is
not true the program continue checking the other conditions since they are at the same indentation while in the nested
conditionals the condition has to be true so the program moves to execute the other conditions.
def f(x,y,z):
if x>y:
elif x>z:
else:
f(2,3,4)
def func(x,y,z):
if x==0:
if y>z:
if y>10:
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 12/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
print("Finish")
else:
print("Not finished")
else:
else:
func(9,5,7)
To avoid nested conditionals we can use the conditional operators like: "and"
example:
This code:
if x>4:
if y<5:
print('hello')
print('hello')
References:
Downey, A. (2015). Think Python: How to think like a computer scientist. Conditionals and Recursion. (p 41).
156 words
This is nice, you really think like a computer scientist. I find the distinction between nested and chained conditionals
helpful. Keep it up!
23 words
Hi Fuoad,
That's a good explanation about chained conditionals versus nested conditionals. I suggest you format your post a little
more, it's kind of hard to read the code since there's no spacing on them. Good work though.
38 words
Part 1:
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 13/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Chained Conditionals and a nested conditional are both considered to be statements in python. They both share if/elif/else
flow controls. Looking closely at what the difference is, we can say that in “chained Conditional” the flow controls are all
intended to the same depth, whereas, “Nested Conditional”, can include the flow controls at various different depths.
Part 2:
As studied in this week’s material, deeply nested conditionals can become difficult to read and therefore we can focus on using
the logical operators like “and”, “or” and “not” to make it a bit more digestible to understand and follow.
Example of nested conditional than contain two branches. A simple statement can be noted on the first branch. The second
branch contains another if statement, which has two branches. Those two branches are both simple statements, although they
could have been conditional statements too.
Simplified:
References:
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press. This book is licensed under Creative
Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0).
197 words
Re: Discussion Unit 3
by Stephen Chuks - Monday, 29 November 2021, 3:45 AM
very good points from you Wilmer. Your explanations are professional and shows you know what you're talking about. and
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 14/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Very nice explanation, your programs are simple and concise, good citation, and clearly you know what are you talking
about. Great job.
22 words
Great work in reflecting the distinction between chained and nested conditionals. I would like to recommend you to
practice using script mode and present your program in scripts than using interactive mode. Nevertheless, you did it well.
37 words
Your effort to this question is extremely good. Your input makes us understand the topic even more. You have given simple
but sensible examples on the conditions. Your effort has not gone to waste. You have made me learn more. Keep it up!
43 words
Discussion Forum Unit
3
Describe
the difference between a chained
conditional and a nested
conditional. Give your own example of each.
Chained
conditionals
are flows of programming executions, where we use to check multiple conditions
of possibilities. For
example, we have learned from chapter 5 of the book Think
Python an if…...else is used to check two conditions (Downey,
2015, p. 41).
Below
is an example of chained conditionals. Here I am going to use chained
conditionals that check final exam pass marks for
an English course.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 15/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Output
is as follows
Nested
Conditionals are
flows of programming executions inside other conditional execution. “One
conditional can also be
nested within another” (Downey, 2015, p. 42).
Output
for the status of disability=no
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 16/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Output
for the status of disability=yes
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 17/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Reference
201 words
Tags:
Unit 3 Discussion Forum
Discussion Forum Unit 3.docx
P li k Sh
Great job, I like the way you created your examples, the examples are very clear, easy to read and to understand the flow
of the data.
26 words
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 18/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Great work in using reasonable examples. I learned some concepts from your programs regarding the topic. Thanks for
sharing.
19 words
You have put a great effort and shed a lot of light in this discussion. Your examples are totally simple and very clear. Thank
you for your input in the discussion. You clearly understand the topic. You handled explanations extremely well. Keep it up!
44 words
Hi Samrawi,
The way you formatted you post makes it really easy to read and understand. It shows how much time you put into this.
Nicely done, good job!
29 words
Hello Samrawi,
I really love the way you showed your script and the output in the chained conditionals. The work is actually voluminous
for the nested conditionals. Nevertheless, I appreciate the efforts you put into it. Thank you
38 words
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 19/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Describe the difference between a chained conditional and a nested conditional. Give your own example of each.
The difference between chained and nested conditional is that chained conditional can be used to check multiple conditions at
the same time, using if, elif, and else. We can chain as many conditions as we need using Elif, to do the action required by each
condition.
In the following example, I chained 4 conditions checking different names printing different characteristics per name, if the
name typed using print function was in one of the conditions would print a characteristic, otherwise will print sorry I don’t
know you.
# Chanied conditionlas
if name == "John":
else:
#Nested conditionals are a piece of code where there is an if-else inside of an if-else, this only will be checking one condition
at the time. The problem with this is when we have a lot of nesting conditionals the indentation can be very tricky as we have
to respect the python syntax rule of spaces.
In the following example, there are 3 questions using the input function to get some information from the user and after
getting the information, the nested conditionals will evaluate the data entered, if the gender is a woman will say 'You are a
woman, named user's name', then will check if the age is greater than 30, if it is will print you are a woman older than me,
otherwise will print the opposite. Same with the man's condition.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 20/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
if gender == 'boy':
else:
else:
else:
This example has only one nested condition, as it was easier to explain you could add as many nested conditionals as you
need but as I mentioned before it will be very hard to keep track of the indentation, even if we used a IDE to help us to format
the program.
The strategy to keep the nested conditional easy to read we could use logical operators(and, or, not), these operators will help
us to create one condition in a single line, this way we will not get confused while reading the code and debugging if we need
to.
# This conditional checks that color1 is equal to red and color2 is equal to blue and color3 is equal to purple,
# if any of this condition is false will automatically skip the line and will run the command from else,
# Otherwise if both conditions are true will print I like red, blue and purple too.
else:
Same program using nested conditionals, using the same variables from the previous exercise, color1, color2 and color3 :
if color1 == "red":
if color2 == "blue":
if color3 == "purple":
else:
629 words
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 21/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
P li k Sh
Hi Juan, I really like your examples because they are pretty different than mine in a good way. However, it would have
been even better if you had included the outputs for all your inputs. For example, I may be missing something, but when I
copied and pasted your third example and I am not getting either output from both conditional. I would love to see the
outputs. Thanks for the posting.
72 words
Thank you, the 3 example as is mentioned is using the same color inputs from the previous example
If you run only the conditionals nothing will happen or will say the color1, color2 and color3 are not defined.
I've been debugging and finally found the solution to the issue. All I had to do was remove this part --> ("What
color do you like?"). Great examples!
28 words
Great work Juan, you have explained both chained and nested conditional clearly. I have learned more about chained
conditional from you. You have also demonstrated them with neat examples.
29 words
Hi Juan,
I really like the format of your post, it's very clean and easy to understand. It's nice to see the explanations you put as well.
This shows the time you put into it. I'm a little biased on your nested conditionals example though since it only assumes
two genders, would be nice if you made the woman an elif statement and the non-male/female options as an else
statement. US is pretty big with the LGBTQ+ community when I lived there, so many different people. Keep up the good
work though!
92 words
Permalink Show parent
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 22/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
A chained conditional is when you use if/elif/else flow controls and they are all indented to the same depth. No nesting. #
Nested conditional. # A nested conditional is when you use if/elif/else flow controls and the conditionals vary in depth to
create a more nuanced sequence of conditionals.
elif is an abbreviation of else if. Again, exactly one branch will be executed. There is no limit of the number
of elif statements but only a single (and optional) final else statement is allowed and it must be the last branch in the
statement.
Nesyed conditionals statements mean that you can use one if or else if statement inside another if or else if statement.
Nested conditionals can become difficult to read, threfore refactoring strategy for avoiding this as it is useful for cleaning up
code or to prepare code for easier extension or reuse
NESTED OUTPUT
if x == y: print('x and y are equal') else: if x < y: print('x is less than y') else: print('x is greater than y') The outer conditional
contains two branches. The first branch contains a simple statement.
CHAİNED PUTPUT
if x > 0: print('x is positive') The boolean expression after if is called the condition. If it is true, the indented statement runs. If
not, nothing happens.
references
HowtoThink Like a Computer Scientist
Allen Downey
224 words
Good job, i would like to add some point into your explanation,
A chained conditional is whenever you have to check different conditions at the same time, using ‘elif’ with this elif you
could add as many conditions to be check and perform the action required by them.
Example:
If a > 5:
elif a == 5: #You can add as many elif you want inside of this chained conditional
else:
The nested conditional is when you have an if-else inside of an if-else, like this. And only check one condition at the time.
if a > 5:
else:
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 23/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
if a == 5:
else:
For your answer I recommend you to, format the text better, as it will be easier for other peers to mark and understand the
program.
-Both
chained conditional and nested conditional consist of compound statements
starting with "if" followed by a body of
three or more conditional
possibilities (branches) using "elif" and/or "else" to be
run. However, nested conditional can only be
formed within the body of chained
conditional using its own statement using "if" followed by branches
that contain more
specific or detailed conditions. As nested conditional can
only be formed within the body of chained conditional, it can be
distinguished
by further inside indentation.
-Using
logical operators such as "and", "or", and "not"
comes in handy when avoiding nested conditionals because they can
combine
multiple different conditions into a single condition.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 24/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
-Below is the equivalent single conditional to the above nested conditional using logical operator "or" and "and":
165 words
I like the creative code, the explanation was great and easy to read an understand, including the outputs was a nice touch,
i think i will start doing that as well.
31 words
Hello Hyun,
You did a great work and the explanation was simple and clear to understand, also using pictures with their discription
make it more easier.
26 words
1* #A chained
conditional is like the name implies, a chain of elif() conditionals that start with an if() statement
and end
with an else() statement which could look like Example 1.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 25/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Example 1.
print("player 1 won the game")
print("player 2 won the game")
elif( x=3 ): #this
can go on forever
print("player 3 won the game")
else:
#closing else:
statement
print("the game has
ended in a draw")
#seeing that this way isn't very efficient, it's better to define a
function
instead, at least for this example.
2*# A nested
conditional is when an if(): statement is used inside another if(): statement.
Example2
else:
if(z=0):
#nested if(): statement
else:
if(z=2):
else:
3*#
To help shorten a nested conditional we can use a strategy like the one in Example3.2.
Example3.1
if(x=1): #Nested if(): statement
print(“player1 has won both games”) #we can do this for all possible combinations
Example3.2
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 26/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
if(z=1 && x=1): #combining both can make it a lot simpler to read even for all possible
combinations
251 words
Hello Yahya,
I really commend your efforts in this work. The code was clearly written and I love your comments throughout the
workflow as they give clarity to your steps.
30 words
The difference between these two concepts chained and nested conditionals are in the depth of indentation. For chained
conditionals the use of if/elif/else statements are somewhat like a chain, the depth of indentation is the same for example.
As you can see the depth of indentation is on the same level. Whereas on nested conditionals, like the word suggests the
depth is nested, how nested it can be is up to the code. Here is an example
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 27/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Deeply nested conditionals are very difficult to read, from a Wikipedia contributor (2021) this is what is sometimes called
spaghetti code sometimes even referred to as a big ball of mud when it comes to the overall application making heavy use
of these principles. To avoid this try the following :
Convert your negative checks into positive checks, for example instead of asking if the variable is null rather assume the
variable is positive and the condition will return a bool of true or false.
Replace your conditionals with guards
Allways return values as soon as possible
Decompose your conditionals into small useful functions
References:
Wikipedia contributors. (2021a, May 19). Big ball of mud. Wikipedia. https://en.wikipedia.org/wiki/Big_ball_of_mud
202 words
Great work using complex and reasonable examples and also pointing out the difference between nested and chained
conditionals clearly. Keep it up.
22 words
Well done, you did a great explanation, it was very clearful to describ your point with the pictures. keep it up!!
21 words
Fouad
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 28/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Hello siphumelelise,
I love the fact that you reference the source of your information for the nested conditionals. You also pointed out in your
explanation and coding that the depth of indentation is on the same level for chained conditionals and nested for nested
conditionals. Kindly review the joining of compound words. some_integer_argument should have been written as
some_Integer_Argument or someIntegerArgument
61 words
Chained conditionals express more than two branches of computation that have different possibilities. (Downey,2015). I
demonstrated with a simple program regarding chained conditionals statements below.
Program
Input:
x = 2
z = 2
if x = z:
print("system OFF")
elif x == z:
print("system asleep")
else:
print("maintenance needed") #Printing string text, 'maintenance needed' if no value turns true.
Output:
system ON
#From my program above, all conditional statements turns true apart from the last else: statement. But only the first true
conditional statement is executed, thats the reason why the program has only one output.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 29/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Nested conditionals are a way to nest one conditional statement into another. (Downey,2015).
Program
Input:
x = 2
z = 2
if (x==z):
print('System Asleep.😇')
else:
if (xz):
print("System Off.")
else:
Output:
System Asleep.😇
#The first conditional statement nests another conditional statement which has three branches of simple statements which
could be conditional statements if needed.
Although deeply nested conditionals can be complex and difficult to read, they can be simplified using logical operators.
(Downey,2015).
My program below demonstrates how a deeply nested conditional can be simplified using a logical operator.
Program
Input:
#Nested conditionals.
x = 2
z = 2
if (x==z):
print('System Asleep.😇')
else:
if (xz):
print("System Off.")
else:
x = 0.2
z = 8
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 30/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
print("System Asleep.😇")
Output:
System Asleep.😇
System Asleep.😇
#The logical operator "<" in the second #simplified nested conditionals, simplifies the program for easy reading and clear
understanding and produces the same output as the deeply nested conditional statements.
Reference
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tea Press.
283 words
Newton, I enjoyed reading your peace, you demonstrated an understanding of the concepts, keep it up.
16 words
QUESTION 1
Describe the difference between a chained conditional and a nested conditional. Give your own example of each. Do not copy
examples from the textbook.
Chained Conditional
A chained conditional contains a series of alternative branches using if, elif, and else statements that are all indented the same
depth. In a chained conditional, there is no nesting. A chained conditional only executes the first branch that has a true
outcome, no matter how many true conditions are in the chain. It runs through all the conditions one after the other until if
finds the true outcome.
Example of chained conditional
x = 40
y = 130
z = 200
if z > x:
elif x < z:
else:
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 31/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Nested conditional
On the other hand, a nested conditional statement is one in which one conditional statement is nested within another
conditional statement. The depths of the if, elif, and else statements in nested conditionals vary. Therefore, a nested
conditional permits the usage of flow controls, but those conditionals have different depth to create more nuance sequence.
x = 10
y = 10
if x < y:
else:
if x > y:
else:
QUESTION 2
Deeply nested conditionals can become difficult to read. Describe a strategy for avoiding nested conditionals. Give your own
example of a nested conditional that can be modified to become a single conditional, and show the equivalent single
conditional. Do not copy the example from the textbook.
Answer: A strategy to avoid nested conditionals is to engage the use of logical operators like “and”, “or”, “not” to create some
flexibility in the statement and simplify them into a single conditional. A typical example is:
if x == y
if y == z
else:
If x == y and y == z
else:
Peter,
Great Explanation you demonstrated an understanding of chained and nested conditionals well, well done.
15 words
Chained conditional
example:
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 32/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
>>>if apple
== "red":
. . . elif apple ==
"green":
. . .
print("Apple will taste sour.")
. . . else:
Nested conditional
example:
>>>if eyes
== “open”:
. . . if body
== “moving”:
. . . else:
. . .
print(“The dog is sleeping soundly.”)
A good strategy to
avoid difficult to read nested conditionals is to try and see if you
can simplify it with logical operators
(Downey, 2015).
Example:
>>>if
days_left == 0:
. . .
print("It's your birthday!")
. . . elif
days_left > 0:
. . . if
days_left < 30:
. . . else:
Modified example:
>>>if
days_left == 0:
. . .
print("Your birthday is coming soon!")
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 33/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
. . . else:
. . .
print("Your birthday is still far.")
Reference:
Downey, A. (2015).
Think Python: How to think like a computer scientist. Green Tea
Press. This book is licensed under Creative
Commons
Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0).
258 words
Janelle,
Well done, you demonstrated an understanding of the concepts, great use of citations, keep it up.
17 words
Hi Janelle,
I really love your examples. They are just great but make sure to add the starting python block of code on one of your
"else" conditional too. The definition are good too.
For chained conditional it has several alternatives, but nested conditional is nesting.
Chained conditional
if n+1 < y:
else:
Nested conditional
if (x+1)==(y+1):
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 34/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
else:
if (x+1)<(y+1):
else:
Hi Mayowa , sorry but I'm not convinced by your definition of the two conditionals. Also your examples.are great but make
sure to starting blocks of code to show that is python code.
Hi Mayowa
Great examples. I liked how you referenced too. Keep up the good work.
15 words
Chained conditionals are conditionals that help programmers to resolve tasks that have multiples possibilities such as
mathematical problems. Generally, they are used when we have more than two possibilities to express like when we do not
have to choose between true or false neither black or white for example, but they might be necessary when we are supposed
to choose one answer within multiple others and this kind of conditionals expression allow us to test each answer till, we find
the right one. While nested conditionals are conditionals expressions that are usually Whitin a first conditional statement (an if
for example) to allow us to explore, treat, or state something when the actual condition is not meet. In some cases, both
chained and nested conditionals can do the same task.
>>> x=y+1
>>> if y>0:
print("x is postiive")
print("x is negative")
>>> else:
>>> y= a
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 35/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
>>> if a==0:
print( x + y is odd)
>>> else:
>>> if a%2==0:
print("x+y is odd")
>>> else:
print("x+y is even")
The the best way to avoid nested conditions is to use logical operators such as AND, OR and NOT(Downey,2015). In fact these
operators can help to simplify conditions and run a program easily.
Example1:
sqrt(x-1)?
>>> if x<1:
>>> else:
>>> If x==1:
print("Impossible")
else:
Example2:
sqrt(x-1)?
else:
The example 2 helps to realize the same answer with one single condition by using the operator “and”.
315 words
Hi Hamidou
Great examples. I liked how you referenced too. Keep up the good work.
15 words
Difference between
a chained conditional and a nested conditional.
1.) Describe
the difference between a chained conditional and a nested conditional. Give
your own example of each.
Do not copy examples from the textbook.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 36/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Ø
The
difference between a chained conditional and a nested
conditional is chained conditional is use when there are more
than two
possibilities. More than two branches are needed (Downey, 2015, p.41), and
nested conditional is an “if else” or “if”
statement inside another “if else”
statement, along with that nested conditionals can become difficult to read
very quickly, so it
is a great idea to avoid them when we can (Downey, 2015,
p.42).
2.) Deeply
nested conditionals can become difficult to read. Describe a strategy for
avoiding nested conditionals.
Give your own example of a nested conditional
that can be modified to become a single conditional, and show the
equivalent
single conditional. Do not copy the example from the textbook.
Ø
Example
of chained conditional and a nested conditional.
chained conditional
correct =
float(input('enter correct: '))
points=
float (input('enter points:'))
def
Grade(correct,points):
grade=correct*points
quote,
grade = Grade(correct,points)
print('your
grade is: {} and: {}'.format(grade, quote))
nested Conditional
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 37/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
def grade
(fail, pass):
if fail == true:
else:
else:
3.
Strategy for avoiding nested conditionals.
Actually,
I have been sitting here for hours finding bugs on my nested conditionals
example on the question above. The
strategy for avoiding nested conditional is
trying to limit it use as much as possible (Downey, 2015, p.42).
Reference
Downey,
A. (2015). Think Python| How to Think Like a Computer Scientist: Vol.
Version 2.2.23 (2nd Edition). Green Tea Press.
https://my.uopeople.edu/pluginfile.php/1404469/mod_page/content/3/TEXT%20-%20Think%20Python%202e.pdf
349 words
Discussion Forum Unit 3.docx
Permalink Show parent
Hi Crystal,
However I do not agree with you strategy to avoid nested conditional as sometimes we need to computate complex task.
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 38/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Hi Crystal
Great examples. I liked how you referenced too. Keep up the good work.
15 words
Chained conditional is using multiple else denoted as "elif" which is short term for "else if". Below program demonstrates if
dice rolled selected between 1 to 3 displays the number; else the program will request to roll dice selected again to achieve
result between 1 to 3.
roll_dice=1
if(roll_dice==1):
elif(roll_dice==2):
elif(roll_dice==3):
else:
Nested condition is if else statement where you might find another if and else statement branched on both or any of them(i.e
under if another if else or else under it another if and else statement). Below code has if and else statement below else
condition.
light_mode="Green"
if(stop_sign=="Red"):
else:
if(stop_sign=="Green"):
else:
light_mode="Green"
if(stop_sign=="Red"):
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 39/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
else:
Reference:
Downey, A. (2015). Think Python: How to Think Like a Computer Scientist. Needham, Massachusetts: Green Tea Press
196 words
All activities close on Wednesdays at 11:55 PM, except for Learning Journals/Portfolios which close on Thursdays at 11:55 PM always
following the clock at the top of the page.
Due dates/times displayed in activities will vary with your chosen time zone, however you are still bound to the 11:55 PM GMT-5
deadline.
Jump to...
Resources
UoPeople Library
Orientation Videos
LRC
Syllabus Repository
Honors Lists
Links
About Us
Policies
University Catalog
Support
Student Portal
Faculty
Faculty Portal
CTEL Learning Community
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 40/41
1/5/22, 1:47 AM CS 1101 - AY2022-T2: Discussion Unit 3
Office 365
Tipalti
Contact us
English (en)
English (en)
العربية(ar)
Data retention summary
Get the mobile app
https://my.uopeople.edu/mod/forum/discuss.php?d=640871 41/41