 # Control Flow Test Data Science

ok I’m confused so there were two questions on the test I just took both that were “What will be printed”

I first got this on

``````x = 0

if x = 0:
print("x is equal to zero.")
elif x >= 0:
print("x is greater than zero.")
else:
print("x is less than zero.")
``````

I thought the answer would be that x is equal to zero would be printed. Turns out its a syntax error

then I got this question

``````x = 5

if x <= 2:
print("This is printed")
if x <= 4:
print("This is also printed")
if x <= 6:
print("Is this printed?")
if x <= 8:
print("This might be printed.")
``````

I assumed that because the first one created an error this one would print nothing. However it said it printed two things “Is this printed” and “This might be printed”

x is defined before either one so I figured the first one would print but it said since the first one wasn’t written as x == 0 it wasnt actually set to 0 why is it not the same in both isn’t x set to 0 in the first and x set to 5 in the second before the code blocks?

If this is a test for school, then we cannot assist you here.

Hi dev6623677336!

Sometimes when working through control flow problems such as these, it can help to map it out. So the first problem you had turned out to be a syntax error - it looks like you figured out why that is.
The second problem is different. These if statements do contain proper conditionals (<=). It still may help to compare and contrast the two problems. How do the loops differ, and what impact does that have as a result?
If you need more help, feel free to reply! 2 Likes

Hi lisalisaj!

This looks like it comes from the Control Flow Quiz in the Data Science Path!

3 Likes

Ok, cool. There was no link associated with it so I wanted to err on the side of caution.

2 Likes

Ahhhhhh I see I’m looking at the wrong spot. I’m thinking that the very first line should be x == 0 on the first problem but it’s after the if that is the problem. Should be if x == 0:

Thank you that really helped me!