The code should be continuous...
1) Create a list named 'numList' with the following numbers: 4, 7, 9, 0, 9, 7, 43, 2, 6, 87
2) Print out the last element in 'numList'
3) Write a loop that prints out ALL the elements in numList (first number printed must be 4)
4) Write a loop that prints out ALL the elements in numList in REVERSE ORDER (first number printed must be 87)
5) Write a loop that prints out all the numbers in numList that are GREATER THAN 10
The code :
numList = [4, 7, 9, 0, 9, 7, 43, 2, 6, 87]
print "This is last element " + `numList[-1]`
print ' '
for x in range(len(numList)):
print numList[x]
print ' '
numList.reverse()
for x in range(len(numList)):
print numList[x]
print ' '
for x in range(len(numList)):
if numList[x] > 10:
print "Greater than 10 got " + `numList[x]`
No comments:
Post a Comment