Ask Question
29 April, 00:02

Consider the following code: x = int (input ("Input an integer: ")) if (x > = 0) : print ("Yay!") else: print ("Boo!") It outputs "Yay!" if the value is positive and "Boo!" if the value is negative. Change the condition so that it only outputs "Yay!" if the value is non-negative (i. e. zero or positive) and even. x > = 0 and x % 2 = = 0 x > = 0 and x % 2 = = 1 x > = 0 or x % 2 = = 1 x > = 0 or x % 2 = = 0.

+1
Answers (1)
  1. 29 April, 01:25
    0
    You have to apply the given condition in if loop.

    Explanation:

    if ((x>=0) && (x%2==0))

    print ("Yay!")

    else

    print ("Boo!")

    if ((x>=0) && (x%2==0)) this statement is enough to check given expectation. the value of x is positive that is checked using x>=0 and also the positive integer should be an even number is checked using the condition (x%2==0). The "&&" operator is used to check whether both the condition is true. So if the value of "x" is positive and even, "Yah!" will be printed. Otherwise "Boo!" will be printed.

    All the other choice goes invalid becoz (x%2==1) will be true only if the number is an odd number.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Consider the following code: x = int (input ("Input an integer: ")) if (x > = 0) : print ("Yay!") else: print ("Boo!") It outputs "Yay!" if ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers