[Tutor] Need help with one problem.

Steven D'Aprano steve at pearwood.info
Wed Feb 15 18:17:13 EST 2017


On Wed, Feb 15, 2017 at 01:00:30PM -0500, Adam Howlett wrote:

> Write an if-else statement that assigns 20 to the variable y if the 
> variable x is greater than 100. Otherwise, it should assign 0 to the 
> variable y.
> 
> Is there an easy way to solve this problem?

Yes. What have you tried?


Hint: here's a similar problem.

"Write an if-else statement that assigns "Hello" to the variable q if 
the variable p is equal to 11. Otherwise it should assign "Goodbye" to 
the variable q."

And here's the answer:

if p == 11:
    q = "Hello"
else:
    q = "Goodbye"


Can you see the pattern? Can you follow that same pattern for your own 
question?


(Hint: use > for "greater than".)


-- 
Steve


More information about the Tutor mailing list