CICS 110 2-6 quizzes
What does the following program print out? (Note in the print statement, parameter end is assigned an empty string.) If it's an infinite loop, type IL in your answer. i = 3 while i > -1: print(i, end='') i -= 1 Answer:
3210
If list = [1, 2, 3, 4, 5, 6] write down the value of list[len(list)//2] in the blank below.
4
A base case in recursion is a. when the function recursively calls itself with a smaller argument b. when the function calls a function other than itself c. when the function returns without recursively calling itself d. when the function recursively calls itself with a larger argument e. when the function uses a loop to avoid infinite recursion
c. When the function returns without recursively calling itself
If list = [1, 2, 3, 4, 5, 6] what would be the value of list[-3]? a.4 b.5 c.1 d.6 e.2 f.3
a. 4
What is the difference between a runtime error and a syntax error? a. A runtime error is caught during the running of code, while a syntax error is caught before the program starts. b. A runtime error stops the program before code can be run, while a syntax error is just visual. c. A runtime error is caught during the running of code, while a syntax error is found after the code is done running. d. A runtime error violates the rules of Python, while a syntax error is correct python code but it doesn't behave as intended. e. There is no difference, an error is an error.
a. A runtime error is caught during the running of code, while a syntax error is caught before the program starts
What are the three properties of an object? (Select all three correct answer to gain full credit. Any incorrect choice will result in partial deduction) a. Identity (ID) b. Type c. Value d. Length e. Name f. Shape
a. Identity (ID) b. Type c. Value
Which of the following is true about a list object in Python? a. It may contain another list b. It is defined using a pair of curly brackets c. It must contain at least one element d. It is immutable e. All elements in a list must be of the same data type
a. It may contain another list
What does the following code print out? def func(n): n **= 2 x = 3 print (func(x)) a. None b. 3 c. 9 d. 6 e. 8
a. None
What's the output of the following program? num=10 while num <= 15: print(num, end=' ') if num == 12: continue num += 1 a. The loop never ends b. 10 11 12 c. 10 d. 10 11 e. 10 11 13 14 15
a. The loop never ends
We want to write code to check the condition that a given location is 'in Massachusetts, but NOT in Western Mass, unless if it's also in Amherst'. Which of the following boolean expression correctly implement this condition? Note that there are more than one correct answers. Select all correct answers to gain full credit. Any incorrect selection will result in partial deduction. (In case you don't know: Amherst is in Western Mass, which is in turn in Massachusetts). a. in_amherst or (in_massachusetts and (not in_western_mass)) b. in_massachusetts and (not in_western_mass) and in_amherst c. in_massachusetts and ((not in_western_mass) or in_amherst) d. in_massachusetts and (not (in_western_mass and in_amherst)) e. in_massachusetts or (in_amherst and (not in_western_mass))
a. in_amherst or (in_massachusetts and (not in_western_mass)) c. in_massachusetts and ((not in_western_mass) or in_amherst))
If my_list is a list that contains at least one element. Which of the following is true about calling my_list.pop()? a. it removes and returns the last item in the list b. it reports an error as the index is not provided c. it reports an error as list does not support the pop() method d. it removes and returns the first item in the list e. it removes all items from the list
a. it removes and returns the last item in the list
What's the result (in terms of data type and value) of the following expression? "23" + '45' a. string '2345' b. float 68.0 c. string '68' d. The expression results in an Error e. integer 68 f. integer 2345
a. string '2345'
Which expression below is a correct implementation of the condition "x and y are NOT both larger than 50" (i.e. it returns True if x and y are NOT both larger than 50, and False otherwise)? a. X<=50 and y<=50 b. not (×<=50 and y<=50) c. (×>50 and y<=50) or (×<=50 and y≥50) d. X<=50 or y<=50 e. not (×>50 or y>50)
a. x<=50 and y<=50
What does the following program print out? (Hint: pay attention to the indentation). If the loop never ends, write IL in your answer. for c in 'abc': print(c*2, end='') print('-', end='') Answer:
aabbcc-
What would the following code print out? def func(a): print(a**a) print(func(2)) a. 4 4 b. 4 None c. None 4 d. 4 2 e. 4
b. 4 None
Positive or negative numbers with no decimal point.
int
What is the data type of variable var in the loop body. In other words, in the loop body if you print out type(var) what would be the result? for var in range(len('abcde')): # loop body
int
What is the data type of variable var in the loop body. In other words, in the loop body if you print out type(var) what would be the result? g = {(1, 2): 'a', (2, 3): 'b', (3, 4): 'c'} for var in range(len(g)): # loop bod
int
What is the data type of variable var in the loop body. In other words, in the loop body if you print out type(var) what would be the result? lis = [True, False, True, False, True] for var in range(len(lis)): # loop body
int
Select every statement that is valid Python code, meaning code that doesn't violate any of the rules of Python we have talked about. (Any incorrect choice will result in partial deduction) a. import = "Math" b. 4 = x c. Def = "function" d. name = " 'Luigi' " e. 8 * * (3 + 5) f. 10variable = 10 g. x + 5 = 10
c. Def = "function" d. name = " 'Luigi' "
A collection of characters.
str
What is the data type of variable var in the loop body. In other words, in the loop body if you print out type(var) what would be the result? d = {'a': 1, 'b': 2, 'c': 3} for var in d: # loop body
str
What is the data type of variable var in the loop body. In other words, in the loop body if you print out type(var) what would be the result? for var in 'abcde': # loop body
str
What is the data type of variable var in the loop body. In other words, in the loop body if you print out type(var) what would be the result? f = {(1, 2): 'a', (2, 3): 'b', (3, 4): 'c'} for var in f: # loop body
tuple
What is the data type of variable var in the loop body. In other words, in the loop body if you print out type(var) what would be the result? h = [(1,2),(3,4),(5,6)] for var in h: # loop bod
tuple
Which of the following is a Python operator used to compute the remainder of a division? a. math.mod() b. // c. mod() d. / e. % f. **
e. %
Let's take a look at a more complex nested loop where the inner loop iterations depends on the outer loop variable. for x in range(5): for y in range(x+1): print('*', end='') print() To understand how this nested loop works, let's first look at the outer (x) loop. It's aforloop over range(5), which that means the value ofxwill be0, 1, 2, 3, 4at each outer loop iteration. Now let's look at the inner loop: it iterates overrange(x+1). So when the outer loop variablexis0, the inner loop goes over range(x+1)=range(0+1)=range(1), which runs just 1 iteration, printing out 1 star. When the outer loop variablexis1, the inner loop goes over range(1+1)=range(2), which runs 2 iterations, printing out 2 stars. And so on and so forth. In the end, how many stars in total does this nested loop print out? answer:
15
If alist = [0, 1, 2, 3, 4, 51, write down the value of alist [len(alist) //31. Write 'Error' if there is an index out of range error. Answer:
2
Which of the following are valid list object in Python? Select all that are valid. Any incorrect selection will result in partial deductions. A.[1, 2, (3, 4)] B.1, '2', 3.0 C.'[1, 2, 3]' D.('1', '2', '3') E.[] F.[1, '2', 3.0] G.[True]
A. [1, 2, (3,4)] E. [] F. [1, '2', 3.0] G. [True]
Does it evaluate to True or False? '1'+'2' == '3'
False
Does it evaluate to True or False? 1.0 == '1.0'
False
Does it evaluate to True or False? 1==(2==False)
False
In Python the following two expressions result in the same value: 1 + 2 * 3 - 4 (1 + 2) * (3 - 4) Select one: True False
False
Select its value True or False 'True' == True
False
True or False: Recursion is computationally more efficient than solving the same problem using loops
False
True or False: Any problem that can be solved using recursion can be solved using loops (though it may require a lot more code)
False
Does it evaluate to True or False? (1==2) == False
True
Does it evaluate to True or False? bool('False')
True
In Python casting an object into a new data type doesn't change the underlying object at all, instead, it creates a new object with the desired data type. Select one: True False
True
Select its value True or False 0 == 0.0
True
Select its value True or False 4//2 ==2.0
True
Select its value True or False False == False
True
True or False: Recursion is a conceptually simple and elegant way to solve certain problems (e.g. computing fractals, permutations of items, etc.)
True
True or False: Any problem that can be solved using recursion can be solved using loops (though it may require a lot more code)
True
What's the output of the following code? (Please read both the code and the choices carefully) def division(a, b): try: div = a / b print(f'Quotient: {div}') except: print(f'Cannot divide {a} by {b}') division (10, 2) division (2, 0) division ('13',2) a. Quotient: 5.0 Cannot divide 2 by O Cannot divide '13' by 2 b. Quotient: 5.0 Cannot divide 2 by 0 Cannot divide 13 by 2 c. Quotient: 5.0 Quotient: 0.0 Quotient: 6.5 d. Quotient: 5.0 Cannot divide 2 by Quotient: 6.5 e. It raises a runtime error
b. Quotient: 5.0 Cannot divide 2 by 0 Cannot divide 13 by 2
What does the following code print out? print(print(print('a'))) a. It raises a runtime error b. a None None c. The printout depends on the memory address of the print function d. None None a e. a
b. a None None
Which of the following is a Python operator used to compute power / exponentiation, such as 24? a. % b. ** c. math.power() d. math.log() e. ^ f. //
b. **
What's the output of the following program? num = 10 while num <= 15: print(num, end=' ') num += 1 if num == 12: break a. 10 b. 10 11 c. The loop never ends d. 10 11 12 13 14 15 e. 10 11 12
b. 10 11
Which of the following statements is true about a function's return value? a. A function can return multiple objects simultaneously and they can be either mutable or immutable b. A function can only return one object v c. A function can return multiple objects simultaneously as long as they are all immutable objects d. The value a function returns can only e. a mutable object Oe. The value a function returns can only be an immutable object
b. A function can only return one object
Which of the following is TRUE? a. A function must have at least one parameter in its definition b. A function's parameters must be variables -- they may not be expressions c. A function must have at least one return statement in the function body d. A function can only return strings and numbers, and may not return other types of objects e. When calling a function, the arguments passed to the function must be variables -- they may not be expressions
b. A function must have at least one parameter in its definition
If lis is a list, and i is an integer whose value is between [0, len(lis)-1] (inclusive on both ends). Which of the following is/are true about lis[i:i+1]? Select all correct answers. Any incorrect selection will result in partial deduction. a. It's a list containing one element lis[i+1] b. It's a list containing one element lis[i] c.It's a tuple containing two elements lis[i] and lis[i+1] d. It's a list containing two elements lis[i] and lis[i+1] e.If i is equal to len(lis)-1, it will raise an index out of range error
b. It's a list containing one element lis[i]
Which of the following is not a part of the computer model we discussed in class? a. Processor b. Power supply c. Memory d. Input e. Output
b. Power supply
What type of error, if any, is with the following piece of code? lis1 = [1,2, 3,4,5] adder = 5 bigger_list = lis1 + adder a. There is no error b. Runtime error c. Logic error d. Syntax error
b. Runtime error
Using functions as objects can be useful in a number of applications. For example, let's say we have four functions: draw_circle, draw_triangle, draw_square, draw_dot. We want to define a draw function such that when a user passes in an shape number, namely 1, 2, 3, or 4, it calls one of the above four functions respectively. Normally you would have to write an if-elif sequence like below. if shape==1: draw_circlel) elif shape==2: draw_triangle() elif shape==3 draw_square() elif shape==4: draw_dot () But using function objects we can dramatically simplify the code to just 1 line. Which of the following is equivalent to the above if-elif sequence? a. [draw_circle, draw_triangle, draw_square, draw_dot] [shape] b. [draw_circle, draw_triangle, draw_square, draw_dot] [shape]() c. [draw_circle(), draw_triangle(), draw_square(), draw_dot()][shape] d. [draw_circle, draw_triangle, draw_square, draw_dot] (shap
b. [draw_circle, draw_triangle, draw_square, draw_dot][shape]()
Given the following two sets: setA = {1, 2, 3, 4, 5} setB = {1, 3, 5, 7, 9} What is the result of setA.union(setB)? a.{1, 2, 3, 4, 5, 1, 3, 5, 7, 9} b.{1, 2, 3, 4, 5, 7, 9} c.{2, 4, 7, 9} d.{1, 3, 5} e.{7, 9}
b. {1, 2, 3, 4, 5, 7, 9}
Continuing from the question above, what is the result of setA.symmetric_difference(setB)? a. {5, 3, 1} b. {7, 9, 2, 4} c. {2, 4} d. {7, 9} e. {1, 3, 5} f. None of the above
b. {7, 9, 2, 4}
What is the data type of variable var in the loop body. In other words, in the loop body if you print out type(var) what would be the result? lis = [True, False, True, False, True] for var in lis: # loop body
bool
What would the following code print out? def func(a): return (a, a) print(func(2)) a. (2 2) b. 2 2 c. (2, 2) d. [2, 2] e. None f. [2 2]
c. (2,2)
What's the output of the following program? num=10 while num <= 15: print(num, end=' ') num += 1 if num == 12: continue a. The loop never ends b. 10 11 12 c. 10 11 12 13 14 15 d. 10 12 13 14 15 e. 10 11 13 14 15 f. 11 13 14 15
c. 10 11 12 13 14 15
Below is a nested loop. How many iterations does the print statement run? In other words, how many stars does it print out? for i in range(5): for j in range(4): print('*', end='') a. 12 b. 30 c. 20 d. 4 e. 9
c. 20
Which one of the following expressions is a correct way to check if an integer A is divisible by 4 (i.e. is a multiple of 4)? The expression should return True if A is divisible by 4 and False otherwise. a. int(A / 4) == A // 4 b. A % 4 != 0 с. А / 4 == A // 4v d. A / 4 == 0 e. A // 4 == 0
c. A / 4 == A // 4
Which of the following statements is true about a function in Python? a. When calling a function, the arguments passed to the function must be variables -- they may not be expressions b. A function must have at least one return statement in the function body c. A function's parameters must be variables -- they may not be expressions d. A function may not call another function in its body
c. A function's parameters must be variables--they may not be expressions
If fruits = ['apple', 'banana', 'orange', 'pear'] what would the list become after running fruits.insert(1, fruits.pop (3)) a. ['apple', 'pear', 'orange', 'banana'] b. I'pear', 'banana', 'orange', 'apple'] c. I'apple', 'pear', 'banana', 'orange'] v d. I'pear', 'apple', 'banana', 'orange'] e. It leads to an index-out-of-range error f. I'apple', 'orange', 'pear', 'banana']
c. ['apple', 'pear', 'banana', 'orange']
The code below uses nested if statements: if color == 'red': if style < 3: print('A') elif style < 5: print('B') else: print('C') elif color == 'blue': print('D') else: print('E') Which of the following conditions will make the above code print out 'B'? a. color is 'red' and style is 5 b. color is 'red' and style is 6 c. color is 'red' and style is 3 d. color is 'blue' and style is 4 e. color is 'blue' and style is 3
c. color is 'red' and style is 3
Which of the following correctly removes the item 'Google' from the list? companies = ['Apple', 'Microsoft', 'Google', 'Amazon'] a.companies.pop(-1) b.companies.pop(3) c.companies.remove('Google') d.companies.remove(2) e.companies.pop('Google')
c. companies.remove('Google')
In Python, objects like integers and strings can't be modified once they are created. These objects are called ____ a. dynamic typing b. unchangable c. immutable d. fixed e. mutable f. static typing g. constant
c. immutable
A(n) _____ is a named item used to hold a value. a. function b. constant c. variable d. expression e. integer f. string
c. variable
Given the following nested dictionary: addresses = { 'John Smith': {'number': 1, 'street': 'van meter dr', 'zip': '01002'}, 'Mary Ann' : {'number': 15,'street': 'spring st', 'zip': '95050'}, 'Alice Wang': {'number': 98,'street': '5th ave', 'zip': '10001'} } Which code below correctly prints out the zip code and only the zip code of each person? a. for person in addresses: print(addresses[person].zip) b. for person, zip in addresses.items(): print(zip) c. for zip in addresses['zip']: print(zip) d. for person in addresses: print(addresses[person]['zip']) e. for name in addresses: print(addresses.get(name).get(zip))
d. for person in addresses: print(addresses[person]['zip'])
What would the following code print out (please read the code carefully)? def convert(grade): if grade >= 90: return 'A' elif grade >= 80: return 'B' if grade >= 70: return 'C' else: return 'D' print(convert(85)) print('--') a. C -- b. A B C -- c. A C -- d. B C -- e. A -- f. A B -- g. B --
d. B --
Assuming b is a positive integer, Which of the following functions correctly calculates the power a° (in other words a**b)? a. def pow(a, b): return 1 if b==1 else a*pow(a, b-1) b. def pow(a, b): return b if a==1 else a*pow(a-1, b) c. def pow(a, b) : return a if b==1 else a*pow(a-1, b) d. def pow(a, b): return 1 if b==0 else a*pow(a, b-1) e. def pow(a, b): return a if b==0 else a*pow(a, b-1)
d. def pow(a,b): return 1 if b==0 else a*pow(a, b-1)
What's the output of the following program? courses = { 110 : 'Intro Python', 160 : 'OOP', 210 : 'Data Structures' } for x in courses: print(x, end=',') a. 110:Intro Python,160:OOP,210:Data Structures, b. x,x,x, c. 110,Intro Python,160,OOP,210,Data Structures, d. 110,160,210, e. Intro Python,OOP,Data Structures,
d. 110,160,210,
Given the following definition of a class: class Rectangle: def _init_(self, w, h, c='gray'): self.width = w self. height = h self.color = c which of the following code can correctly create an object of the Rectangle class without any runtime error? Select all that are correct. Any incorrect selection will result in partial deductions. a. Rectangle(width=10, height=20, color='yellow') b. Rectangle(self, 10, 20, 'yellow') c. Rectangle (10) d. Rectangle(10, 20) e. Rectangle() f. Rectangle(10, 20,'yellow')
d. Rectangle(10, 20) f. Rectangle(10, 20, 'yellow')
In Python, if you call the type() function on an object, what does it return? a. The unique identifier representing the object's memory address b. The value of the object c. The size (number of bytes) of the object in memory d. The data type of the object e. The timestamp that the object was created
d. The data type of the object
If you use the id() function on an object, what does it return? a. The value of the object b. The length of the object c. The number of instances of the object d. The unique identifier representing the object's memory address e. The timestamp that the object was created f. The data type of the object
d. The unique identifier representing the object's memory address
What's the value of newlis after running the code below? Please read the code carefully. lis = [ ['a', 'b', 'c'], 'd'] newlis = [s+'!' for s in lis[0]] a. ['a,'!, b', "!', 'ch'!', 'd', "!'] b. [['a!', 'b!', 'c!'], 'd!'] c. ['a!', 'b!', 'c!', 'd!'] d. ['a!', 'b!', 'c!'] e. An error is raised
d. ['a!', 'b!', 'c!']
Which of the following statements is False about the if-elif-else statement? a. You may have an if without any elif following it b. You may have an if without any else following it c. In a single if-elif-else sequence, only one branch will run -- it's not possible for more than one branch to run d. elif can appear either before or after else e. elif and else must appear after if, they may not appear on their own without an if
d. elif can appear either before or after else
When defining a class in Python, the constructor function a. may take any number of parameters b. may have any name of your choice c. must have the same name as the class d. must be named _init_ e. must take exactly one parameter
d. must be named __init__
Given a positive integer n, which of the following generates the sequence 0, 1, 2, 3 ... n? (0 and n are both included in the sequence) a. range(0, n-1) b. range(1, n) c. range(0, n) d. range(0, n+1) e. range(1, n+1)
d. range(0, n+1)
Which of the following can be used to create a string from an integer in Python? a. string() b. convert(string, int) c. int() d. str() e. Str() f. Int()
d. str()
Below is a program that counts how many negative values there are in the list of temperatures. What should be the correct code for the blank? temperatures = [-2, 8, 4, -7, 18, 3, -1] count = 0 for t in temperatures: if _____: count = count + 1 print(f'Total negative temperature values: {count}') a. t[temperatures] < 0 b. temperatures < 0 c. temperatures.t < 0 d. t < 0 e. temperatures[t] < 0 f. t[i] < 0
d. t < 0
What is the output of the code below? a = [1,2,3] a.pop(2) a.remove(2) a.append(86) a.insert(0,'Apple') a.pop() print(a) a.[] b.['Apple', 1, 3] c. It reports an error d.['Apple',1] e.[1, 86] f.[1, 3]
d.['Apple',1]
What should be the initial values of x and y in order for the loop below to terminate (i.e. the break statement will run at some point)? while True: print(x, y) x += 1 y -= 1 if x==y: break a. (x-y) must be a positive even integer b. The loop will always terminate no matter what the initial values of x and y are c. (y-x) must be a positive odd integer d. (x-y) must be a positive odd integer e. (y-x) must be a positive even integer
e. (y-x) must be a positive even integer
What's the output of the following program? num = 10 while num <= 15: print(num, end=' ') if num == 12: break num += 1 a. The loop never ends b. 10 11 12 13 14 15 c. 10 11 d. 10 e. 10 11 12
e. 10 11 12
11. How many iterations does the following while loop run? x = 8 while x>1: x/=2 print('All done') a. 2 b. 7 c. The loop never ends d. 8 e. 3 f. 4
e. 3
Assume numbers is a list of integers (the integer values are allowed to be positive or negative). Which of the statements below is true about the following program? min_num = 0 for n in numbers: if n < min_num: min_num = n print(min_num) a. If numbers contain a mix of positive and negative integers, it will the largest negative integer b. If numbers contain a mix of positive and negative integers, it will print out 0 c. If numbers contain a mix of positive and negative integers, it will print out the smallest positive integer d. If numbers contain only strictly negative integers, it will print out 0 e. If numbers contain only strictly positive integers, it will print out 0
e. If numbers contain only strictly positive integers, it will print out 0
If n is a positive integer, what does the following function compute? def foo(n): return 0 if n<1 else foo(n-2) a. It computes n/ /2 b. It computes (n+1)//2 c. It computes n//2+1 d. For some values of n, it leads to an infinite recursion e. It always returns 0
e. It always returns 0
Regarding the boolean expression: (n % 10 == 0) and (n % 5 != 0) (assuming n is an integer), which of the following statements is true? a. It's always True b. It's True when n is divisible by 5 but not by 10, and False otherwise c. It's True when n is divisible by 10, and False otherwise d. It's True when n is divisible by 50, and False otherwise e. It's always False
e. It's always False
How many iterations does the following loop run? x = 1 while True: if x == 4: break if x == 3: continue x += 1 a. 2 b. 3 c. 4 d. 5 e. The loop never ends
e. The loop never ends
How many iterations does the following while loop run? x = 7 while x > 0: x = (x+1)//2 print('All done') a. 5 b. 0 c. 3 d. 4 e. The loop never ends f. 2
e. The loop never ends
Which of the following is true about a dictionary object in Python? a. Both the keys and values can be any Python objects b. Each key has an index associated with it indicating its position in the dictionary c. The keys must be mutable objects, the values must be immutable objects. d. The keys must be immutable objects, the values must be mutable objects e. Two different keys can be associated with the same value object
e. Two different keys can be associated with the same value object
What's the list generated by the following list comprehension? [i**2 for i in range(1, 5)] f. 12, 4, 6, 81 a. 10, 1, 4, 9, 16] b. 12, 4, 6, 8, 101 c. 10, 1, 4, 9, 16, 251 d. 11, 4, 9, 16, 251 e. [1, 4, 9, 161 v
e. [1, 4, 9, 16]
What's the output of the following code? Please read the code carefully. def double (c): C *= 2 print([double(c) for c in '123']) a. ['246'] b. I'2', '4', '6'] с. ['123123'] d. [', '2', '3'1 e. [None, None, None] f. ['11', '22', '33'1
e. [None, None, None]
Which of the following is a valid name for a variable in Python? a. 1_counter b. Friendly's c. my-excavator d. while e. false
e. false
Which expressions below is a correct implementation of the condition "neither x nor y is larger than 20" (i.e. the expression returns True if neither x nor y is larger than 20, and False otherwise)? Select all that are correct. Incorrect choices will result in partial deductions. a. not (x>20 and y>20) b. x>20 or y>20 c. x>20 and y>20 d. x<=20 or y<=20 e. not (x>20 or y>20) f. x<=20 and y<=20
e. not (x>20 or y>20)
Identify the error with the code written below. The program is supposed to ask the user for two numbers, then output the subtraction of the two numbers. num1 = input("Input the first number") num2 = input("Input the second number") print(num1 - num2) a. print() can only print out strings, not numbers. b. The input() function cannot take parameters inside its parentheses c. The data types of the two variables num1 and num2 must be declared first d. If one number is an integer and the other is a float, you cannot subtract them e. num1 and num2 are both strings, subtracting two strings is invalid.
e. num1 and num2 are both strings, subtracting two strings is invalid.
Which of the following tasks can only be implemented using a while loop and can NOT be implemented using a for loop? a. iterate over every character in a string b. check whether a given integer is a prime number or not c. print out all elements in a list d. sum up all integers from 1 to 100 e. repeatedly print out random numbers until the user enters the string 'quit'
e. repeatedly print out random numbers until the user enters the string 'quit'
Which of the choices is a correct line of code that can replace XXX in the program below, resulting in valid, error-free code? def calc_sum(a, b):return a + b XXXprint(y) a. y = calc_sum(9) b. y = calc_sum(4 + 5) c. y = calc_sum('a', 10) d. y = calc_sum() e. y = calc_sum(4 + 5, 5 + 6) f. calc_sum(y, 4, 5)
e. y = calc_sum(4 + 5, 5 +6)
What would the following code print out if grade = 85 (please read the code carefully)? if grade >= 90: print('A') elif grade >= 80: print('B') if grade >= 70: print('C') else: print('D') print('--') a. C -- b. A -- c. B -- d. A B C -- e. A B -- f. B C -- g. A C --
f. B C --
Given a positive and odd integer n, which of the following generates the sequence 1, 3, 5, 7 ... n? (1 and n are both included in the sequence) a.range(1, n+2) b.range(1, n) c.range(1, n, 2) d.range(1, n+1) e.range(1, n-1, 2) f.range(1, n+1, 2)
f. range (1, n+1, 2)
Positive or negative numbers with a decimal point.
float