1 Which of the following statements is true about this Boole

1) Which of the following statements is true about this Boolean expression?

The expression is never true

The expression is true for numbers between 0 and 100

The expression is true for numbers greater than 100

The expression is true for numbers less than 0

The expression is always true

2) In the pseudocode below:

What will be the output from calling loop(6) (separate each output with a single space)?


Hint: You may find it easier to write a Python program to calculate the above instead of trying to work out the answer on paper. Whichever way you find easier is acceptable.

3) In the pseudocode below:

What will be the output from calling fibo(5) (separate each output with a single space)?


Hint: You may find it easier to write a Python program to calculate the above instead of trying to work out the answer on paper. Whichever way you find easier is acceptable.

4) In the following pseudocode:

What will be the output from this loop (separate each output with a single space)?


Hint: You may find it easier to write a Python program to calculate the above instead of trying to work out the answer on paper. Whichever way you find easier is acceptable.

5) In the pseudocode below:

What will be the output when the main module is called (separate each output with a single space)?

Hint: You may find it easier to write a Python program to calculate the above instead of trying to work out the answer on paper. Whichever way you find easier is acceptable.

6) In the pseudocode below:

What will be the output when the main module is called (separate each output with a single space)?

Hint: Pay particular attention to the type of the variable named \"half\" in the \"halve\" function. Integers are always whole numbers, so if half is an integer, then:

half = 3/2

would result in half being equal to 1 (not 1.5, which isn\'t a whole number).

Additional hint: you might decide that it\'s easier to write the Python code for the above pseudocode and to see what the program actually produces instead of trying to just figure it out on paper. If so, then

Set half = n / 2

can be written in Python as:

half = int(n / 2)

7) What will the output be for the following pseudocode:

Separate each output with a single space.

The expression is never true

The expression is true for numbers between 0 and 100

The expression is true for numbers greater than 100

The expression is true for numbers less than 0

The expression is always true

Solution

1>

The expression is never true.

2>Input: loop(6)

def fibo_2(n):
if n == 1:
return 1
elif n==2:
return 1
else:
return fibo_2(n - 1) + fibo_2(n - 2)

def loop(n):
counter = 0
while (counter< n):
counter = counter + 1
print(fibo_2(counter),end=\' \')
  
loop(6)

3>Input: loop(5)

4>

def loop_rule(n):
   if n %2==0:
       n=n/2
   else:
       n=n*3+1
   print(n,end=\' \')
   return n

def loop(n):
   count = 0
   while (n != 1):
       count = count + 1
       n=loop_rule(n)
   return count

print(loop(3))

5>

def halve(n):
   half = n / 2
   return half

def log2(n):
   lg2 = 0
   while (n > 1):
       n = halve(n)
       lg2=lg2+1
   return lg2


print(log2(8))
print(log2(4))
print(log2(1))
print(log2(13))

7>

counter = 1

while (counter < 10):
   counter=counter+2
   print(counter,end=\' \')

1) Which of the following statements is true about this Boolean expression? The expression is never true The expression is true for numbers between 0 and 100 Th
1) Which of the following statements is true about this Boolean expression? The expression is never true The expression is true for numbers between 0 and 100 Th
1) Which of the following statements is true about this Boolean expression? The expression is never true The expression is true for numbers between 0 and 100 Th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site