Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

14.) 1 point The following code differs from the code above by one word. What do

ID: 3603347 • Letter: 1

Question

14.) 1 point
The following code differs from the code above by one word. What does
the following Python code return?
a = 10 > 5
b = 14 <= 27
c = 99 > 100
a and b or c
For 5 bonus points: explain why the code in question 14 returns the result that it
did.

Explanation / Answer

##PROBLEM 1-1 (1/1 point) ##Suppose x = "pi" and y = "pie". The line of code x, y = y, ##x will swap the values of x and y, resulting in x = "pie" and y = "pi". ## ##True True - correct ##False ##PROBLEM 1-2 (1 point possible) ##Suppose x is an integer in the following code: ##def f(x): ## while x > 3: ## f(x+1) ## ##For any value of x, all calls to f are guaranteed to never terminate. ##True ##False True - correct ##PROBLEM 1-3 (1/1 point) ##A Python program always executes every line of code written at least once. ##True ##False - correct ##PROBLEM 1-4 (1 point possible) ##Suppose you have two different functions that each assign a variable called x. Modifying x in one function means you always modify x in the other function for any x. ##True ##False - correct ##PROBLEM 1-5 (1 point possible) ##Assume a break statement is executed inside a function. The function call will always terminate without executing any remaining code inside that function. ##True ##False - correct ##PROBLEM 1-6 (1/1 point) ##Let d be a dictionary. If d[a] == d[b] then a == b. ## ##True ##False - correct ##PROBLEM 1-7 (1/1 point) ##Suppose you run the following code: ##def f(L): ## L.append(4) ##x = [1,2,3] ##f(x) ## ##The variableL is an alias for the variable x. ##True True - correct ##False ##PROBLEM 1-8 (1/1 point) ##A program that keeps running and does not stop is an example of a syntax error. ## ##True ##False - correct ##PROBLEM 1-9 (1/1 point) ##A recursive algorithm must always have at least one base case. ## ##True True - correct ##False ##PROBLEM 1-10 (1/1 point) ##Any number that can be represented as a decimal fraction can be represented exactly in floating point representation in Python. ## ##True ##False - correct ##PROBLEM 2-1 (1/1 point) ##What data type is the object myst: ## ##myst = ( { 1: [1,1], 2: [2,2]}, { 'a': ['a',1], 'b': ['b',2] } ) ##tuple tuple - correct ##list ##dictionary ##None of the above ##PROBLEM 2-2 (1/1 point) ##Which of the following is true? ## ##Testing a program and debugging a program are the same thing. ## ##Testing compares program output to the expected output. ##Debugging is a process to study the events leading up to an error. - correct ## ##Testing checks that there is no input on which the program crashes. ## ##Testing is typically done by putting try-except blocks around pieces of code. ## ##PROBLEM 2-3 (1 point possible) ##Assume the statement s[1024] = 3 does not produce an error message. This implies: ## ##type(s) can be str ##type(s) can be tuple ##type(s) can be list ##All of the above - incorrect ##PROBLEM 2-4 (1/1 point) ##Choose the item from the list of potential responses that best matches: "specification" ## ##abstraction abstraction - correct ##mutation ##indentation ##induction ##PROBLEM 2-5 (1/1 point) ##Choose the item from the list of potential responses that best matches: [:] ## ##keyword ##mutation ##cloning cloning - correct ##black box testing ##PROBLEM 3-1 (2 points possible) ##Examine the following code snippet: ##stuff = ["iBoy", "iGirl", "iQ", "iC","iPaid","iPad"] - correct ##stuff = ("iBoy", "iGirl", "iQ", "iC","iPaid","iPad")- correct ##stuff = [ ( "iBoy", "iGirl", "iQ", "iC","iPaid","iPad") ] ##stuff = ( [ "iBoy", "iGirl", "iQ", "iC","iPaid","iPad" ], ) ##stuff = "iPad" ##stuff = 'iPad' ##for thing in stuff: ## if thing == 'iPad': ## print "Found it" ##PROBLEM 3-2 (3 points possible) ##The following Python code is supposed to compute the square of an integer by using successive additions. ##def Square(x): ## return SquareHelper(abs(x), abs(x)) ## ##def SquareHelper(n, x): ## if n == 0: ## return 0 ## return SquareHelper(n-1, x) + x ##Not considering recursion depth limitations, what is the wrong with this implementation of procedure Square? Check all that apply. ## ##It is going to return a wrong value. ##The term Square is a reserved Python keyword. ##Function names cannot start with a capital letter. ##The function is never going to return anything. ##Python has arbitrary precision arithmetic. ##This function will not work for negative numbers. ##The call SquareHelper(abs(x), abs(x)) won't work because you can't have abs(x) as both parameters. ##Nothing is wrong; the code is fine as-is. ##PROBLEM 4 (10 points possible) ##Write a simple procedure, myLog(x, b), that computes the logarithm of a number x relative to a base b. ##For example, if x = 16 and b = 2, then the result is 4 - because 24=16. ##If x = 15 and b = 3, then the result is 2 - because 32 is the largest power of 3 less than 15. ## ##In other words, myLog should return the largest power of b such that b to that power ##is still less than or equal to x. ## ##x and b are both positive integers; ##b is an integer greater than or equal to 2. ##Your function should return an integer answer. def myLog(x, b): ''' x: a positive integer b: a positive integer; b >= 2 returns: log_b(x), or, the logarithm of x relative to a base b. ''' exp = 2 result = 0 if x > b: while result
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote