INTRODUCTION TO COMPUTATIONAL
THINKING AND PROGRAMMING PRACTICE
QUESTIONS
The function definition has no errors. - CORRECT ANSWER-
The function definition has no errors
In the following statements about Python functions, which one is
FALSE?
A function should be defined for one task and should not be too
long.
A function can have at most one return statement.
Functions should be reusable.
A function can be called by other functions.
When designing functions, we should always provide comments. -
CORRECT ANSWER-A function can have at most one return
statement.
In the following statements about recursive functions, which one
is FALSE?
,Recursive functions support the divide-and-conquer problem
solving.
Recursive functions are usually concise and elegant.
A function that invokes itself is called a recursive function.
A recursive function is always efficient than its loop-based
version. - CORRECT ANSWER-A recursive function is always
efficient than its loop-based version.
Which of the following is not an element of iterative
accumulation?
The variable to store the accumulation result.
The print statement to print the result.
The target value in each iteration.
The loop to drive accumulation iteratively. - CORRECT
ANSWER-The print statement to print the result.
Initialize student_counter to zero
While student_counter is less than or equal to ten
Input the next score
Add the score into the total
EndWhile
Set the class average to the total divided by ten
,There are some errors in the above Pseudocode. Please indicate
where the errors are and how to correct them - CORRECT
ANSWER-Initialize total to zero (Must initialize variable before
use)
Initialize student_counter to one (if counter starts from zero, will
be 11 students instead of 10)
While student_counter is less than or equal to ten
Input the next score
Add the score into the total
Add one to student_counter (update looping control variable)
EndWhile
Set the class average to the total divided by ten
Initialize passes to zero
Initialize failures to zero
Initialize student_counter to one
While student_counter is less than or equal to ten
Input the next score
*
*
*
*
*
add one to student_counter
, EndWhile
*
* - CORRECT ANSWER-If the student passed
Add one to passes
else
Add one to failures
EndIf
print the number of passes
print the number of failures
Write the FizzBuzz algorithm using pseudocode.
FizzBuzz is a standard interview problem. The Problem state:
Write a code that prints each number from 1 to 20 on a new line.
Print "Fizz" if the number is the multiple of 3. Print "Buzz" if the
number is multiple of 5
For number which is multiple of both 3 and 5 print "FizzBuzz"
The sample run is as follows:
1
2
Fizz
4