Coding Problems - Modules 7+ Flashcards Preview

zPython > Coding Problems - Modules 7+ > Flashcards

Flashcards in Coding Problems - Modules 7+ Deck (5)
Loading 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

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
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)

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)

5
Q

s = ‘Monty Python’

what is the code to return ‘monty’?

A

s[0:5]