
Programming Logic Quiz
Authored by Audrey Fipps
Computers
9th Grade
Used 3+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
20 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Given the following code, what result will be stored in the boolean variable? int numRabbits = 5; bool enoughRabbits = numRabbits > 2 && numRabbits < 7;
true
false
null
Impossible to tell
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
When the following code runs, under what conditions will the "Access granted" message be displayed? string password = "secret"; Console.Write("Enter password: "); string input = Console.ReadLine(); if (input == password || input == "override") { Console.WriteLine("Access granted"); }
input is equal to "secret" OR input is equal to "override"
input is equal to "secret" AND input is equal to "override"
input is equal to "secret" only
input is equal to "override" only
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What expression should replace the ???? below to print the output message if the number of people is less than 5 or greater than 10? Console.Write("How many people are here? "); int people = int.Parse(Console.ReadLine()); if ( ???? ) { Console.WriteLine("Not the right size group"); }
(people < 5) || (people > 10)
(people <= 5) && (people >= 10)
(people < 5 && > 10)
(5 < people < 10)
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What expression should replace the ???? below to ensure the message is printed only if there is exactly one winner? Console.Write("Did player 1 win? "); bool winner1 = bool.Parse(Console.ReadLine()); Console.Write("Did player 2 win? "); bool winner2 = bool.Parse(Console.ReadLine()); if (????) { Console.WriteLine("There can only be 1 winner"); }
winner1 ^ winner2
winner1 && winner2
winner1 || winner2
winner1 ! winner2
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What expression should replace the ???? below to ensure the message is printed only if neither winner is true? Console.Write("Did player 1 win? "); bool winner1 = bool.Parse(Console.ReadLine()); Console.Write("Did player 2 win? "); bool winner2 = bool.Parse(Console.ReadLine()); if (????) { Console.WriteLine("There is no winner"); }
(!winner1) && (!winner2)
(winner1 && winner2)
(winner1 ^ winner2)
(winner1 || winner2
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which single if() expression can replace the nested if() statements below to ensure the message is still printed under the same conditions? Assume age is a properly initialized int variable and passedDriverTest is a properly initialized bool variable. if (age >= 16) { if (!passedDriverTest) { Console.WriteLine("Old enough, but still can't drive"); } }
if ( (age >= 16) && (!passedDriverTest) )
if ( (age >= 16) || (passedDriverTest) )
if ( age && !passedDriverTest )
if ( age && (passedDriverTest >= 16) )
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which logical operator works against a single input Boolean value or expression?
!
&&
||
^
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?