CMPT 141.3 Practice Exam
22 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which of the following is an example of an algorithm?

  • A box of parts for building a desk
  • A recipe for baking a cake (correct)
  • A movie theater schedule listing showtimes
  • A voting ballot listing candidates and their political parties
  • What is the value of p after the given initializations?

  • 10.0
  • 11.5
  • 11.0 (correct)
  • 13.0
  • In total, how many function calls can be found in this program?

  • 4
  • 2 (correct)
  • 1
  • 3
  • What does the function 'max()' return in the program?

    <p>The length of the longer name string</p> Signup and view all the answers

    What type of value does the function 'float()' attempt to produce?

    <p>Floating-point number</p> Signup and view all the answers

    Which option correctly checks if the string variable s represents a digit?

    <p>C.s.isdigit()</p> Signup and view all the answers

    What is the correct way to import the math library using an alias m?

    <p>import math as m</p> Signup and view all the answers

    What will the value of the expression s[-1:-len(s)-1:-1] be when s is 'DetectivePikachu'?

    <p>'uhcakiPevitceteD'</p> Signup and view all the answers

    Evaluate the expression s[1:len(s):4] for s = 'DetectivePikachu'. What is returned?

    <p>'etPc'</p> Signup and view all the answers

    Which expression will evaluate to TRUE given x = 4 and y = 77?

    <p>x &gt; y or x &gt; 0</p> Signup and view all the answers

    Which of the following expressions evaluates to TRUE?

    <p>not (x == y and x &gt; 10 or y &gt; 10)</p> Signup and view all the answers

    What will the console output be after running the given program regarding speed and turbo?

    <p>50</p> Signup and view all the answers

    What will the program print when ptype is 'grass' and level is 3?

    <p>unknown</p> Signup and view all the answers

    Which version of the formatTime() function would display 1:35 when called with print(formatTime(95))?

    <p>Version 1</p> Signup and view all the answers

    What is the correct function definition to print 'Hello, Pikachu!'?

    <p>def greet(s):</p> Signup and view all the answers

    Which line of code correctly fills in the BLANK to print 1234 to the console?

    <p>answer = combine_digits(12, 34)</p> 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?

    <p>int(s)</p> Signup and view all the answers

    Which version of the formatTime() function causes an error due to a typo?

    <p>Version 2</p> Signup and view all the answers

    What is the outcome of calling formatTime() with a negative totalMinutes value?

    <p>It returns a formatted string with negative hours and minutes.</p> Signup and view all the answers

    Which function version does not return any value when checking print(formatTime(95))?

    <p>Version 3</p> Signup and view all the answers

    Which version of the greet function correctly captures the argument passed?

    <p>def greet(s):</p> Signup and view all the answers

    Signup and view all the answers

    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.

    Quiz Team

    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.

    More Like This

    Use Quizgecko on...
    Browser
    Browser