Log In

Cmis 102 Programming 2

I’m working on a programming practice test / quiz and need an explanation to help me understand better.

Question 1 (10 points)

undefined

Which of the following is the correct sequence of statements to output whether the first letter of the string ‘first’ is an f?

Question 1 options:

ordinal = ‘first’
print(ordinal.checkfirst(‘f’))

ordinal = ‘first’
print(ordinal.startswithf())

ordinal = ‘first’
print(ordinal.startswith(‘f’))

ordinal = ‘first’
print(ordinal(‘f’).check())

Question 2 (10 points)

undefined

What would be output by the following statements?

word = ‘welcome’
print(word[1:1])

Question 2 options:

w

we

No output

e

Question 3 (10 points)

undefined

Which of the following would be output by this code?

word = ‘string’
print(word[6])

Question 3 options:

g

It would generate an IndexError

t

s

Question 4 (10 points)

undefined

Which of the following conditions checks whether the string ‘middle’ alphabetically follows ‘beginning’ and precedes ‘ending’?

Question 4 options:

‘beginning’ != ‘middle’ and ‘middle’ == ‘ending’

‘beginning’ < ‘middle’ < ‘ending’

‘beginning’ < ‘middle’ or ‘middle’ < ‘ending’

‘middle’ < ‘beginning’ and ‘ending’ < ‘middle’

Question 5 (10 points)

undefined

Which of the following is the correct program to count the number of occurrences of the letter r in the string ‘carrot’?

Question 5 options:

vegetable = ‘carrot’
count = 0
for letter in vegetable:
if letter == ‘r’:
count = count + 1
print(count)

vegetable = ‘carrot’
count = 0
for letter in vegetable:
if vegetable[i] == ‘r’:
count = count + 1
print(count)

vegetable = ‘carrot’
count = 0
for ‘r’ in vegetable:
count = count + 1
print(count)

vegetable = ‘carrot’
count = 0
for letter r in vegetable:
if r == ‘r’:
count = count + 1
print(count)

Question 6 (10 points)

undefined

Assuming the variable animal initially contains the string ‘mouse’, which of the following is the correct way to change animal to become ‘moose’?

Question 6 options:

animal = animal[:2] + ‘o’ + animal[3:]

animal[2] = ‘m’

animal[3] = ‘m’

animal = animal[3:] + ‘o’ + animal[:2]

Question 7 (10 points)

undefined

What would be output by the following statements?

fruit = ‘apple’
print(‘pl’ in fruit, ‘pa’ in fruit)

Question 7 options:

False False

True True

True False

False True

Question 8 (10 points)

undefined

Which of the following will be output by the following code?

word = ‘more’
index = 0
while index > len(word):
print(word[index])
index = index + 1

Question 8 options:

m
o
r
e

m
o
r

It would generate an IndexError

No output

Question 9 (10 points)

undefined

Which of the following will be output by this program?

word = ‘ladder’
count = 0
for letter in word:
if letter == ‘d’:
count = count + 1
print(count)

Question 9 options:

5

6

2

4

Question 10 (10 points)

undefined

What would be output by the following statements?

word = ‘mississippi’
print(word.find(‘iss’), word.find(‘iss’, 2))

Question 10 options:

2 5

2 2

1 1

1 4