Podcast
Questions and Answers
Which of the following is an example of an algorithm?
Which of the following is an example of an algorithm?
What is the value of p after the given initializations?
What is the value of p after the given initializations?
In total, how many function calls can be found in this program?
In total, how many function calls can be found in this program?
What does the function 'max()' return in the program?
What does the function 'max()' return in the program?
Signup and view all the answers
What type of value does the function 'float()' attempt to produce?
What type of value does the function 'float()' attempt to produce?
Signup and view all the answers
Which option correctly checks if the string variable s represents a digit?
Which option correctly checks if the string variable s represents a digit?
Signup and view all the answers
What is the correct way to import the math library using an alias m?
What is the correct way to import the math library using an alias m?
Signup and view all the answers
What will the value of the expression s[-1:-len(s)-1:-1] be when s is 'DetectivePikachu'?
What will the value of the expression s[-1:-len(s)-1:-1] be when s is 'DetectivePikachu'?
Signup and view all the answers
Evaluate the expression s[1:len(s):4] for s = 'DetectivePikachu'. What is returned?
Evaluate the expression s[1:len(s):4] for s = 'DetectivePikachu'. What is returned?
Signup and view all the answers
Which expression will evaluate to TRUE given x = 4 and y = 77?
Which expression will evaluate to TRUE given x = 4 and y = 77?
Signup and view all the answers
Which of the following expressions evaluates to TRUE?
Which of the following expressions evaluates to TRUE?
Signup and view all the answers
What will the console output be after running the given program regarding speed and turbo?
What will the console output be after running the given program regarding speed and turbo?
Signup and view all the answers
What will the program print when ptype is 'grass' and level is 3?
What will the program print when ptype is 'grass' and level is 3?
Signup and view all the answers
Which version of the formatTime() function would display 1:35 when called with print(formatTime(95))?
Which version of the formatTime() function would display 1:35 when called with print(formatTime(95))?
Signup and view all the answers
What is the correct function definition to print 'Hello, Pikachu!'?
What is the correct function definition to print 'Hello, Pikachu!'?
Signup and view all the answers
Which line of code correctly fills in the BLANK to print 1234 to the console?
Which line of code correctly fills in the BLANK to print 1234 to the console?
Signup and view all the answers
Given the definition of isdigit(), what should replace BLANK to convert string s to an integer if s contains only digits?
Given the definition of isdigit(), what should replace BLANK to convert string s to an integer if s contains only digits?
Signup and view all the answers
Which version of the formatTime() function causes an error due to a typo?
Which version of the formatTime() function causes an error due to a typo?
Signup and view all the answers
What is the outcome of calling formatTime() with a negative totalMinutes value?
What is the outcome of calling formatTime() with a negative totalMinutes value?
Signup and view all the answers
Which function version does not return any value when checking print(formatTime(95))?
Which function version does not return any value when checking print(formatTime(95))?
Signup and view all the answers
Which version of the greet function correctly captures the argument passed?
Which version of the greet function correctly captures the argument passed?
Signup and view all the answers
Signup and view all the answers
Flashcards
Algorithm Example
Algorithm Example
An algorithm is a set of instructions for solving a problem. A recipe for baking a cake follows a specific sequence of steps to achieve the desired outcome.
Variable Initialization
Variable Initialization
Assigning an initial value to a variable before using it in calculations.
Integer Division (//)
Integer Division (//)
Dividing two integers and discarding the remainder.
Function Call (max)
Function Call (max)
Signup and view all the flashcards
Function Call (len)
Function Call (len)
Signup and view all the flashcards
String Concatenation
String Concatenation
Signup and view all the flashcards
Type Casting (float)
Type Casting (float)
Signup and view all the flashcards
Console Output (print)
Console Output (print)
Signup and view all the flashcards
formatTime() (Version 1)
formatTime() (Version 1)
Signup and view all the flashcards
formatTime() (Version 2)
formatTime() (Version 2)
Signup and view all the flashcards
formatTime() (Version 3)
formatTime() (Version 3)
Signup and view all the flashcards
formatTime() (Version 4)
formatTime() (Version 4)
Signup and view all the flashcards
greet() Function
greet() Function
Signup and view all the flashcards
combine_digits() Function
combine_digits() Function
Signup and view all the flashcards
isdigit() Method
isdigit() Method
Signup and view all the flashcards
Converting to Integer
Converting to Integer
Signup and view all the flashcards
isdigit()
isdigit()
Signup and view all the flashcards
Importing a Library
Importing a Library
Signup and view all the flashcards
String Slicing with Negative Indices
String Slicing with Negative Indices
Signup and view all the flashcards
String Slicing with Step
String Slicing with Step
Signup and view all the flashcards
Logical Operators (and, or, not)
Logical Operators (and, or, not)
Signup and view all the flashcards
if-elif-else Statements
if-elif-else Statements
Signup and view all the flashcards
Variable Scope
Variable Scope
Signup and view all the flashcards
Conditional Execution
Conditional Execution
Signup and view all the flashcards
Study Notes
Exam Information
- Marks: 75
- Time: 180 minutes
- Exam type: Practice final examination
- Course: CMPT 141.3, Department of Computer Science, University of Saskatchewan
Part I - Multiple Choice
-
Question 1: Algorithm example.
- Answer: A recipe for baking a cake.
-
Question 2: Value of p.
- Variables: x=3.3, y=2.2, z=1.1, a=3, b=2, c=5, p=1.5+c*b
- Answer: C. 11.5
-
Question 3: Value of q.
- Variables: x=3.3, y=2.2, z=1.1, a=3, b=2, c=5, q=x-a/c+z
- Answer: D. 3.4
-
Question 4: Value of r.
- Variables: x=3.3, y=2.2, z=1.1, a=3, b=2, c=5, r=x+a*b/c
- Answer: E. 1.42
-
Question 5: Function calls count.
- Answer: 2
-
Question 6: Console output
- Variables: a = 7
- Answer: D. 7.0
-
Question 7: Version of the function formatTime.
- Input: formatTime(95)
- Answer: D. Version 4
-
Question 8: Line of code to print "Hello, Pikachu!"
- Code: message = "Hello," + s + "!"
- Answer: E. def greet(s):
-
Question 9: Line of code to print 1234.
- Answer: C. answer = combine_digits(12, 34)
-
Question 10: Code to convert the string s to an integer.
- Answer: C. s.isdigit()
Part II - Written Answers
-
Question 47: Frostbite warning determination.
- The function should:
- Accepts temperature and windspeed
- Return True if a frostbite warning is needed; false otherwise.
- If temp is less than -40 or (temp is less than -25 and windspeed is greater than or equal to 20), issue the warning.
-
Question 48: Sum of even numbers up to 1000.
- The program should compute the sum of all even numbers from 1 to 1000 (inclusive).
- Answer: Calculate the sum of even numbers using a loop.
-
Question 49: Two-letter permutations of the string "ABCDEFG".
- The code should output all possible combinations of two letters from the string "ABCDEFG", maintaining order matters when generating different two-letter combinations.
-
Question 50: Adding "Ash" to the end of classlist.
- Answer: classlist.append("Ash")
-
Question 51: Names from classlist starting with "A".
- Answer: [name for name in classlist if name[0] == "A"]
-
Question 52: Student names with grades of 80 or higher.
- The program should iterate through the student grades (from the dictionary classgrades) and print the student names if their grade is 80 or greater.
-
Question 53: Word count in a text file.
- Answer: This program reads a file, splits each line into words, counts the number of words in the file, and prints out the total word count.
Other questions (number 54, 55, 56, 57)
- These questions involve writing recursive functions and solving problems based on algorithm analysis and implementations
- The responses will include pseudocode
- The exam involves a lot of conceptual and technical details for understanding program implementation
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge with this practice final examination for CMPT 141.3 at the University of Saskatchewan. It includes multiple choice questions covering algorithms, variable values, function calls, and console outputs. Prepare effectively with this essential review tool.