Questions from quizzes and tests. Flashcards

1
Q

What method could you use to take a string consisting of a sentence and inserting into a list?

A

x = string.split()

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

Define a function called myfunc that takes in a string, and returns a matching string where every even letter is uppercase, and every odd letter is lowercase. Assume that the incoming string only contains letters, and don’t worry about numbers, spaces or punctuation. The out string can start with either an uppercase or lowercase, so long as letters alternate throughout the string.

A

def myfunc(string):
new_string=’’
for i in range(len(string)):
if i%2==0:
new_string=new_string+string[i].upper()
else:
new_string=new_string+string[i].lower()
return new_string

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