A+ Answers




Part 1 : Rewrite the following for loop Python statements using while loop. [10 points]

phrase = "Iowa State University"


index = 0



for ch in phrase:

if (ch == "t") or (ch == "T"):

print ch + " at index " + str(index)

index += 1





Part 2 : Find the output of the following script in Python. Note: All statements are valid. [15 points]



a.



myList = [1, 2, 3, 4, 5]



for i in range(1,5,2):

print myList[i]



b.



myList = ["aaa", "bbb", "ccc", "ddd", "eee", "fff"]



i = -1



while i > len(myList)*-1:

print myList[i]

i -= 1



c.



myList1 = [1, 2, 3]

myList2 = [1,2]



for r in myList1:

for c in myList2:

print r+c , "\t" ,

print