IS-240 Final Exam
Given str1 = "Life, the universe and everything." what does str1.rfind("rev") return? a. -1 b. 26 c. 15 d. 0
-1
Determine the value of the expression: "all clear".title().count('a') 2 -1 1 2
1
Determine the output: x=1 while x<5: print(x) x+=1 1234 12345 2345 234
1 2 3 4
Determine the following output: total=0 num=1 while num<5: total+=num num+=1 print(total) 1 5 10 0
10
In the string literal "Life, the universe and everything." the substring "verse" begins at position _____ and ends at position_____. a. 13, 17 b. 12, 17 c. 13, 18 d. 12, 18
13, 17
Determine the following output: num=3 while num<15: num+=5 print(num) 18 3 5 15 18
18
Determine the output: x=1 while x<5: x+=1 print(x) 2345 1234 12345 234
2 3 4 5
What will the following line of Python display? print(round(22.5)) a. 22 b. 23 c. 22.5 d. this is a logic error
22
Determine the output: num=3 while True: num=2*num if num>15: break print(num) 24 3 0 6
24
Determine the value of the expression: len("brrr")
4
Determine the value of the expression: "Mississippi".rfind("ss") 2 3 5 6
5
Determine the value of the expression: "Hello World!".lower().find('wo') 5 6 7 -1
6
Determine the output displayed. **Assume the response to the input is a isvowel=False letter=input("Enter a letter: ") letter=letter.upper() if (letter in "AEIOU"): isvowel=True if isvowel: print(letter, "is a vowel.") elif (not(65<=ord(letter)<=90)): print("You did not enter a letter.") else: print(letter, "is not a vowel.") a is a vowel. A is a vowel. You did not enter a letter. a is not a vowel
A is a vowel.
In Python, variable names may begin with _____________. a. a letter b. an underscore c. both a & b d. none of the above
A letter and an Underscore
Given the Python statement: value = ( 42, "universe", "everything) which statement is illegal in Python? a. value.append(35) b. value.extend([5, 7]) c. value.insert(1, "hitchhiker") d. all of the above
All of the above
The parentheses of the range function can contain ____________ values. a. one b. two c. three d. all of the above
All of the above
Determine the output displayed: if "": print("An empty string is true.") else: print ("An empty string is false.") An empty string is true. An empty string is false. Error An empty string is true. An empty string is false
An empty string is false
Determine the output: oceans=["Atlantic", "Pacific", "Indian", "Arctic", "Antarctic"] i=len(oceans)-1 while i>=0: if len(oceans[i])<7: del oceans[i] i=i-1 print(", ".join(oceans)) Atlantic, Pacific, Antarctic Atlantic, Pacific, Indian , Arctic, Antarctic
Atlantic, Pacific, Antarctic
The statement a /= 5 is an example of a(n) ____________. a. augmented assignment b. syntax error c. logic error d. integer division
Augmented assignment
Determine the value of the expression: "brrr".upper
BRRR
The ____________ statement causes an exit from anywhere in the body of a loop. a. break b. elif c. pass d. continue
Break
Combining two strings to form a new string is called ____________ a. concatenation b. joining c. stringing d. slicing
Concatenation
Determine the output displayed. **Assume the response to the input is 6 if length<1: cost=3.00 #cost in dollars else: cost=3.00+((length-1)*2.50) result="Cost of cloth is ${0:0.2f}.".format(cost) print (result) Cost of cloth is $3.00. Cost of cloth is $12.50. Cost of cloth is $6.00. Cost of cloth is $15.50.
Cost of cloth is $15.50
Determine the output: age=12 gender="m" while age>=12 and gender=="f": print ("Abc") print("Def") Def Abc Def AbcDef
Def
Using different inputs and outputs on a flowchart to test an algorithm is called _______________. desk checking interpreting flow charting debugging
Desk Checking
A combination of numbers, arithmetic operators, and parentheses that can be evaluated is called a numeric ____________. a. expression b. operations c. literal d. all of the above e. none of the above
Expression
Assuming the value of a is 2 and the value of b is 3, then state whether this statement evaluates to True or False: a**b=b**a
False
Chained methods are executed from right to left.
False
Continue statements cannot be used with if-statements.
False
Determine whether the condition evaluates to True or False "knight".startswith('n')
False
Determine whether the condition evaluates to True or False (7<34) and ("7"<"34")
False
Determine whether the condition evaluates to True or False True and False
False
Determine whether the condition evaluates to True or False isinstance(32.,int)
False
In a hierarchy chart, details on how modules work should be included.
False
In the program development cycle, the first step in writing instructions to carry out a task is to determine how to process the input to obtain the desired output
False
Indentation is not semantically meaningful in Python
False
Logic errors are the easiest type of error to locate
False
Numeric expressions may not contain variables.
False
The relational operators cannot be applied to lists or tuples.
False
Variables cannot be assigned string values, only numeric values
False
You should never use elif when test conditions are mutually exclusive.
False
not((x < 0) or word.isalpha())
False
The mechanical and electrical devices of a computer are referred to as_______________. hardware software peripherals programs
Hardware
Objects that cannot be changed in place are called ___________. a. immutable b. mutable c. static d. unchangeable
Immutable
Determine the result: q=1 while q>0: q=3*q-1 print(q) Infinite loop 2 0 2 5
Infinite loop
Determine the results: num=0 while True: num=1 print(num) num+=1 infinite loop-only displaying the number 1 1234 135
Infinite loop-only displaying the number 1
Determine the value of the expression: "king lear".title() King Lear king lear KING LEAR KING lear
King Lear
Which one of the following Python objects can be changed in place? a. list b. number c. string d. tuple
List
Each execution of the body of a loop is called a(n) ____________. a. pass b. repetition c. circle d. job
Pass
The ____________ statement is a do-nothing statement. a. pass b. void c. break d. continue
Pass
Determine the output displayed: number=5 if number<0: print("negative") else: if number==0: print("zero") else: print("positive") negative zero positive negative zero positive
Positive
Which programming tool uses English-like phrases with some Python terms to outline the task? Pseudocode Algorithm Hierarchy Chart Flowchart
Pseudocode
Determine the value of the expression: "Python"[-10:10]
Python
Instructions in a Python program are called _____________. Source Code editor code debugging code files
Source Code
Determine the output displayed: gpa=3.49 result="" if gpa>=3.5: result="Honors" print(result + "Student") Honors Student Honors Student " " Student (an empty space before the word Student)
Student
Determine the following output a=10 b=10 if a = b: print("same") same Nothing gets printed Syntax Error 10
Syntax Error
Determine the following output: number=6 if number>5 and <9: print ("Yes") else: print("No") Yes No Nothing gets printed Syntax Error
Syntax Error
A string cannot be concatenated with a number
True
Assuming the value of a is 2 and the value of b is 3, then state whether this statement evaluates to True or False: ((5-a)*b)<7
True
Assuming the value of a is 2 and the value of b is 3, then state whether this statement evaluates to True or False: (a*a<b) or not(a*a<a)
True
De Morgan's law can be applied from left to right or from right to left.
True
Determine the output displayed: print('A'<'B'<'C') True False ABC Nothing is displayed
True
Determine whether the condition evaluates to True or False "Duck"<"Duck" + "Duck"
True
Determine whether the condition evaluates to True or False "th" in "Python"
True
Determine whether the condition evaluates to True or False 'B'>'?'
True
Determine whether the condition evaluates to True or False 'J'>='J'
True
Determine whether the condition evaluates to True or False isinstance(32,int)
True
Determine whether the condition evaluates to True or False not False
True
Flowcharts are time-consuming to write and difficult to update
True
Given x = 5, y = 7 and z = "kitten" what does the following condition evaluate to? (x + y) / 2 == len(z) a. True b. False c. it cannot be determined because integers are being mixes with strings d. it cases a Traceback error
True
In order for two tuples to be equal, they must have the same length and corresponding items must have the same value.
True
Lists are mutable
True
Pseudocode is typically more compact than a flowchart
True
Python does not allow for out of bounds indexing for individual characters of a string.
True
Python is case-sensitive
True
When numbers are used as conditions, 0 evaluates to False.
True
not((x < 0) and word.isalpha())
True
A ________________ is any person who runs a program user programmer coder computer
User
The names given to values stored in memory in Python are called a. variables b. quantities c. statements d. literals
Variables
Which variable name is invalid? Selected Answer: a. X-ray b. XRaY c. X_R_A_Y d. xray256
X-ray
change=356 if change >=100: print("Your change contains", change//100, "dollars.") else: print("Your chnage contains no dollars") Your change contains no dollars Your change contains 3 dollars. Your change contains 3.56 dollars. Your change contains 4 dollars.
Your change contains 3 dollars.
Given the Python statement: number=int(input("Enter a whole number: ")) What will be the output if the user enters 17.9? a. a Traceback error message b. 17 c. 18 d. 17.1
a Traceback error message
An if-elif-else statement can contain ____________ clauses. a. any number of b. 1 c. 2 d. 10
any number of
Determine the output: list1=['a','b','c','d'] i=0 while i<(len(list1)-1): i+=1 print(list1[i]) bcd abcd bcde abc
b c d
Which function returns the single-character string of the character with ASCII value n for nonnegative numbers? a. chr(n) b. ascii(n) c. ord(n) d. string(n)
chr(n)
When an if-else statement needs to allow for more than two possible alternatives, you use a(n) ____________ clause. a. elif b. nested c. fi d. else
elif
Which programming tool graphically depicts the logical steps to carry out a task and show how the steps relate to each other? a. flowchart b. hierarchy chart c. algorithm d. pseudocode
flowchart
In a while loop, the line beginning with while is called a(n) ____________. a. header b. intro c. precursor d. starter
header
Which programming tool is used to show how the different parts of a program relate to each other? a. hierarchy chart b. flowchart c. pseudocode d. algorithm
hierarchy chart
Which code gives you the same results? if (a==7): print("seven") elif (a!=7): print("eleven") if (a==7): print("seven") else: print("eleven") if (a==7): print("seven") elif (a==11): print("eleven") if (a==7): print("seven") elif (a!=7): print("eleven") if (a==7): print("seven") else (a!=7): print("eleven")
if (a==7): print("seven") else: print("eleven")
A(n) ____________ loop is one that never ends. a. infinite b. unterminated c. boundless d. executing
infinite
Using a while loop to ensure a proper response is received from a request is called ____________. a. input validation b. verification c. input identification d. user validation
input validation
Determine the value of the expression: "Python"[5]
n
When one loop is contained in the body of another loop, it is said to be ____________. a. nested b. entangled c. surrounded d. blocked
nested
Determine the value of the expression: "Python"[-4:4] th tho oht ht
th
When comparing two lists of different lengths, if all items pairs match up to the end of the shorter sequence, which sequence is said to be the lesser of the two? a. the shorter sequence b. the longer sequence c. they cannot be compared if they are different lengths d. relational operators cannot be used with lists
the shorter sequence
Determine the value of the expression: "Python"[2:]
thon
What Python loop repeatedly executes a block of statements as long as a certain condition is met? a. while b. for c. do d. repeater
while
Determine the value of the expression: "Python"[-5:-1]
ytho