Coding Problems - Modules 7+ Flashcards

1
Q

Write a function that takes a string as an argument and displays the letters, one per line. Do not use for loop.

A

index=0
fruit=”apple”
while index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write a function that takes a string as an argument and displays the letters backward, one per line. Do not use for loop.

A
index=1
fruit="apple"
while index<=len(fruit):
    letter=fruit[-(index)]
    print(letter)
    index+=1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write a function that takes a string as an argument and displays the letters, one per line. Do not use while loop.

A

fruit=”apple”
for letter in fruit:
print(letter)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Use loops to output the following: Jack, Kack, Lack, Mack, Nack, Ouack, Pack, and Quack.

A

prefix=”JKLMNOPQ”
suffix=”ack”

for letter in prefix:
____print(letter+suffix)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

s = ‘Monty Python’

what is the code to return ‘monty’?

A

s[0:5]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly