QUESTION 2
Boolean or "truth-valued" expressions are how we express conditions that control choices and repetition in computer languages. Consider the following Python Boolean expression, where variables alpha, beta, and gamma are of type Boolean:
alpha and (beta or gamma)
In any algebraic notation there are usually several different ways of writing the same expression. For instance, in integer arithmetic the value of expression '4 x (5 + 2)' is numerically equivalent to that of expression '(4 x 5) + (4 x 2)'.
Which of the following Boolean expressions is logically equivalent to the one above?
a |
(alpha or beta) and gamma |
|
b |
(alpha and beta) or (alpha and gamma) |
|
c |
(alpha and beta and gamma) |
|
d |
(alpha or beta) and (alpha or gamma) |
|
e |
not (not alpha) |
|
f |
(not alpha) and (not beta) or (not gamma) |
QUESTION 4
This is a MULTIPLE ANSWER question, which means you are able to select one or more answers as being correct. Note that this does not necessarily mean that there are multiple correct answers. In any case, select all the answers you believe are correct. (NB: There are no part marks awarded for multiple answer questions.)
Consider the following block of Python code, where the variables blue, green and red have integer values.
red = 0
if blue <
green:
if green
> 4:
red
= 5
else:
red
= 6
Consider the case when the code is executed and the first condition (i.e., blue < green) evaluates to False.
In this case, which of the following statements is true?
a |
Variable red will have the value 6 when the code terminates. |
|
b |
Variable blue will be less than variable green when the code terminates. |
|
c |
The second condition (i.e., green > 4) will be evaluated. |
|
d |
Variable red will have the value 5 when the code terminates. |
|
e |
Variable red will have either the value 5 or 6 when the code terminates. |
|
f |
Variable red will have the value 0 when the code terminates. |
|
g |
The second condition (i.e., green > 4) will not be evaluated. |
QUESTION 5
This is a MULTIPLE ANSWER question, which means you are able to select one or more answers as being correct. Note that this does not necessarily mean that there are multiple correct answers. In any case, select all the answers you believe are correct. (NB: There are no part marks awarded for multiple answer questions.)
Consider the following Python predicate functions:
def is_even(number):
return number
% 2 == 0
def is_adult(age):
return age
>= 18
After these expressions have been evaluated:
john = 19
terry = 18
which of the following Python expressions evaluate to False?
a |
(not is_even(terry)) or is_adult(terry) |
|
b |
is_even(terry) and is_adult(terry) |
|
c |
not (is_even(john) or is_adult(john)) |
|
d |
not (is_even(john) and is_adult(john)) |
|
e |
(not is_even(john)) and is_adult(john) |
|
f |
is_even(john) and is_adult(john) |
|
g |
(not is_even(john)) or is_adult(john) |
|
h |
(not is_even(john)) or (not is_adult(john)) |
|
i |
is_even(terry) or is_adult(terry) |
Answers:
Question 2)
-> alpha and (beta or gamma) is equivalent to the
expression
(alpha and beta) or (alpha and
gamma)
-> it is a distributive law in boolean
algebra.
-> Option b is the correct answer.
Question 4)
-> code:
red = 0
if blue < green:
if green >
4:
red = 5
else:
red = 6
-> in above code if first if condition(blue <
green) is not executed
-> then the execution will not enter into that if
condition.
-> results in not modifying the value of variable
red.
-> so red will be equal to 0.(red = 0)
-> finally the answers that are correct are:
-> b) Variable blue will be less
than variable green when the code terminates.
Exp: so no modification in any
variables.
so blue variable
value will be less than green variable when code terminates
-> f) Variable red will have the
value 0 when the code terminates.
Exp: red value is not modified so
red=0.
-> g) The second condition
(i.e., green > 4) will not be evaluated.
Exp: Since first condition
(blue<green) is false. Execution will not enter into inner
if.
This option is
correct only if it also means that the innser else block will not
executed.
-> Correct Options for Question 4: b,f,g
Question 5)
Consider the following Python predicate
functions:
def is_even(number):
return number % 2 == 0
def is_adult(age):
return age >= 18
After these expressions have been evaluated:
john = 19
terry = 18
which of the following Python expressions evaluate to
False?
a. (not is_even(terry)) or is_adult(terry) :
True
b. is_even(terry) and is_adult(terry): True
c. not (is_even(john) or is_adult(john)) : False
d. not (is_even(john) and is_adult(john)) : True
e. (not is_even(john)) and is_adult(john) : True
f. is_even(john) and is_adult(john) : False
g. (not is_even(john)) or is_adult(john) : True
h. (not is_even(john)) or (not is_adult(john)) :
True
i. is_even(terry) or is_adult(terry) : True
So Among all the above expressions: c,f are the
expressions that are evaluated to false.
So Answers are: c,f options.
QUESTION 2 Boolean or "truth-valued" expressions are how we express conditions that control choices and repetition...
Python Activity 05 Boolean Expressions - POGIL (5) - Word Search m Layout References Mailings Review View Help Critical Thinking Questions Programming Structures Sequence Structure Decision or Branching Structure Looping Structure FALSE Which structure best describes the types of Python programs you have written so far? _sequence structure Which structure allows the programmer to create code that decides what code is executed? FYI: Conditional operators, also known as relational operators, are used to compare the relationship between two operands. Expressions...
-1 - (-2). 4. a. / For each of these four expressions, -2 + 6, -(2 + 6), -2 - 6,-(2 - 6) draw a number line (with a consistent scale) and plot the expression on the number line. In each case, show clearly why the expression is located where it is based on the rules for plotting sums, differences, and negatives of numbers on number lines. b. Based on your work in part (a), compare and contrast the four...
QUESTION 1 Which statement results in the value false? The value of count is 0; limit is 10. (count != 0)&&(limit < 20) (count == 0)&&(limit < 20) (count != 0)||(limit < 20) (count == 0)&&(limit < 20) 10 points QUESTION 2 If this code fragment were executed in an otherwise correct and complete program, what would the output be? int a = 3, b = 2, c = 5 if (a > b) a = 4; if (...
Name: True/False & Multiple Choice (2 points each) (True / False ) 2 A char literal '2', a string literal "2", and the numeric literal 2 are identical and stored the same way though they are different types. 3 Since comments do not affect the program execution, you don't need to have it at all. 4. After the following statements are executed, the value of the variable rem is 3. 1. A preprocessor directive line starts with a pound sign...
Homework 2 EE 2420-Spring 2019 Due: Thursday, 2/21/19 @ 11:59 PM 100 points All homework must be typed or written in neat handwriting and scanned or photographed and submitted in PDF format to TRACS. If we cannot easily read your submission, we will not grade your work. Note that files are only submitted if TRACS indicates a successful submission. All homework answers must be submitted individually in your own words and showing all work; however, I encourage you to work...
Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...
One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we will look at ways in which we can model geometric objects comprised of polygons. Here, we want to examine the interactive part. Let’s start by writing an application that will let the user specify a series of axis- aligned rectangles interactively. Each rectangle can be defined by two mouse positions at diagonally opposite corners. Consider the event listener canvas.addEventListener("mousedown", function() { gl.bindBuffer(gl.ARRAY_BUFFER, vBuffer); if...
specifically on finite i pmu r the number of objøcts or ways. Leave your answers in fornsiala form, such as C(3, 2) nporkan?(2) Are repeats poasib Two points each imal digits will have at least one xpeated digin? I. This is the oounting problem Al ancmher so ask yourelr (1) ls onder ipo n How many strings of four bexadeci ) A Compuir Science indtructor has a stack of blue can this i For parts c, d. and e, suppose...
Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...
Case Study, Chapter 64, Introduction to the Integumentary System Alice Bixby, an 83-year-old female client js admifted with a cerebral vascular accident with the aphasia and hemiparesis (paralysis of the right side of the body). The client has global a has difficulty speaking or understanding what is said. The client is incontinent of urine and stool and wears adult incontinent briefs. The client has a thickened diet to nectar consistency because of dysphagia (difficulty swallowing). The client has been turned...