Question 1 (10 points)

Question 1 (10 points)

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

Question 1 options:

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

‘middle’ < 'beginning' and 'ending' < 'middle' 'beginning' < 'middle' < 'ending' 'beginning' < 'middle' or 'middle' < 'ending' Question 2 (10 points) Assuming the variable animal initially contains the string 'rat', which of the following is the correct way to change animal to become 'cat'? Question 2 options: animal[0] = 'c' animal = 'c' + animal[0:] animal = 'c' + animal[1:] animal[1] = 'c' Question 3 (10 points) Which of the following will be output by the following code? word = 'more' index = len(word) - 1 while index > 0:
print(word[index])
index = index – 1

Question 3 options:

r
o
m

e
r
o
m

It would generate an IndexError

e
r
o

Question 4 (10 points)

What would be output by the following statements?

vegetable = ‘carrot’
print(vegetable > ‘spinach’, vegetable > ‘broccoli’)

Question 4 options:

False False

True True

False True

True False

Question 5 (10 points)

What would be output by the following statements?

fruit = ‘Apple’
print(fruit.upper().find(‘P’), fruit.find(‘p’, 3))

Question 5 options:

1 3

0 -1

1 -1

0 3

Question 6 (10 points)

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

Question 6 options:

color = ‘yellow’
count = 0
for letter l in color:
if l == ‘l’:
count = count + 1
print(count)

color = ‘yellow’
count = 0
for letter in color:
if color[i] == ‘l’:
count = count + 1
print(count)

color = ‘yellow’
count = 0
for letter in color:
if letter == ‘l’:
count = count + 1
print(count)

color = ‘yellow’
count = 0
for ‘l’ in color:
count = count + 1
print(count)

Question 7 (10 points)

Which of the following statements outputs whether the first non-blank character of the string contained in the variable named word is a b?

Question 7 options:

print(word.trim().startswith(‘b’))

print(word(‘b’).isfirstnonblank())

print(word.strip().startswith(‘b’))

print(word.firstnonblank(‘b’))

Question 8 (10 points)

Which of the following would be output by this code?

word = ‘string’
print(word[-1])

Question 8 options:

g

It would generate an IndexError

t

s

Question 9 (10 points)

Which of the following will be output by this program?

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

Question 9 options:

6

5

4

2

Question 10 (10 points)

What would be output by the following statements?

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

Question 10 options:

No output

elc

wel

el

Complete Answer:

Get Instant Help in Homework Asap
Get Instant Help in Homework Asap
Calculate your paper price
Pages (550 words)
Approximate price: -
Open chat
1
Hello 👋
Thank you for choosing our assignment help service!
How can I help you?