Ask Question
24 December, 22:28

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.

+4
Answers (1)
  1. 24 December, 22:54
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers