All questions involve this portion of a program:

``````if (y>x and y<z)or(y<x and y>z):
print("You have entered Condition 1")
elif not(x!=y and y!=z):
print ("You have entered Condition 2")
else:
print ("You have entered Condition 3")``````

1. If x = 10 and y = 10, what is the value of z to get Condition 3? Explain why.

2. Explain how you would get condition 2?

3. Give an example (x,y,z) to give condition 3
answer in format: x= ... , y = ..., z = ...

Can someone please help me with these 3 questions, this is a homework assignment I got from my computer science class. I'm finding it a bit complicated and will really appreciate it if anyone can answer these for me.

BTW I am a python beginner so please take it easy on me.

1.Try writing it out on a peice of paper. The first question is easy if you run through what number you would need.
2.any python book will tell you what != means, and 'if not' is self explanatory.
3. will take some thinking about, but after you get the hang of the first two shouldn't be too difficult.

Do what breatheasier said and come back with more specific questions. It would do you no good to have one of us answer theses questions. You'll just get behind as your class moves on.

If you really try hard on this and still can't get anywhere, I suggest you speak with you instructor. They will help you get on track.

What the hell? This is basic math. You fail.

commented: That's not very nice, but very very true :) +15

Get yourself familiar with True and False, and how they apply to AND, OR and NOT (Boolean Algebra).

To start with, what do these mean and what is the order of their evaluation? Post your answer here if you want some help.

``````if (y>x and y<z)or(y<x and y>z):
elif not(x!=y and y!=z):``````

Since you have code, you can answer the first question by brute force. Set x and y to 10, and then loop through increasing values of z to see where you get a response from the third condition. __And Then Figure Out Why.__ After that you should be able to answer question 2.

Edit: Note that an "and" is two if() statements, and an "or" is an if() + elif(). So if it is easier to understand you can rewrite it.

``````if (y>x and y<z)
## becomes
if y > x:
if y < z:
print("You have entered Condition 1 because y > x AND y < Z")
##--- now for the "or"
elif y < x:    ## etc``````

OK people I think I got, just let me know if I'm right.

1. It is impossible to get to condition 3 with those values of x and y.
In order to get to condition 3, "y" must be higher than both the values of "x" and "z" or "y" must be lower
than both the values of "x" and "z".Basically (y>z and y>x) or (y<z and y<x) in condition 3.

2. In order to get to condition 2,the values of "x", "y", and "z" must all be the same.

3. x=1
y=3
z=2

Looks right. I hope you actually tested these. It would only take a minute.

2. In order to get to condition 2,the values of "x", "y", and "z" must all be the same.

Double check this. With my limited tests, it appears that if x == y, it doesn't matter what z is (or y == z and the value of x doesn't matter), which would mean that condition 3 would start with x != y to get by condition 2, and then additional constraints to get by condition 1. I doubt that there is only one set of numbers (which is what you have) to get to condition 3.

Double check this. With my limited tests, it appears that if x == y, it doesn't matter what z is (or y == z and the value of x doesn't matter), which would mean that condition 3 would start with x != y to get by condition 2, and then additional constraints to get by condition 1. I doubt that there is only one set of numbers (which is what you have) to get to condition 3.

This is correct.

The question is "Explain how you would get condition 2?" Changing "the values of "x", "y", and "z" must all be the same" to "the values of "x", "y", and "z" are all the same" might be a better answer. It wouldn't hurt to give a more complete answer, however.

Thanks to everyone who replied to this thread. Now, mods can you please delete this thread since its solved. I don;t think it will have any use anymore.

Thanks to everyone who replied. Mods can you please close this thread. I'm sure it won't be needed anymore.

Thanks to everyone who replied. Mods can you please close this thread. I'm sure it won't be needed anymore.

How could you be so sure? Someone doing a search for 'boolean' and maybe 'python' here or on google might find use out of it. That's how it works. Someone has a question, others try to help, the conversation stays on the site for others that may find it useful in the future.

Haha, I'm not sure that applies in this case.

Haha, I'm not sure that applies in this case.

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.