Flow controls: Conditions · 14 / 22 Exercise Medium

Conditional operator

Objective

Create a Python program that prompts the user for two numbers and responds whether they are positive or if both are positive, using the conditional operator.

Instructions

  1. Prompt the user for a number and store it in a variable named a.
  2. Prompt the user for another number and store it in a variable named b.
  3. Use the conditional operator to evaluate if a is positive and display A is positive or A is not positive based on that evaluation.
  4. Use the conditional operator to check if b is positive and display B is positive or B is not positive based on that evaluation.
  5. Finally, use the conditional operator to determine if both numbers are positive and display Both are positive or Both are not positive as appropriate.
Input
6
4
Output
A is positive
B is positive
Both are positive

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise