COSC Exam 2

27 cards   |   Total Attempts: 188
  

Related Topics

Cards In This Set

Front Back
How many times does the following while loop execute?
N = 10
Count = 0

while Count < N:
print ‘Towson University!’
Count = Count + 1
10
For the array Names, set the value equal to False at index 5
Names[5]=False
Write a while loop that stores the numbers 0 through 9 into a list called List2
Count=0
while count <10:
list2.append(count)
count=count+1
How many times does ‘Hello World’ get printed?
List = [ [1,2,3], [4,5,6], [7,8,9]]
for r in List:
for c in r:
print ‘Hello World’
Create an empty array called names .
Names()=[]
Create a list/array named alphabet that contains the first 5 letters of the alphabet

alphabet=['A', 'B', 'C', 'D', 'E']
Replace the element ‘B’ in the array named alphabet, with the new value ‘z’

aphabet[1]=z
Print the last item in the list alphabet

print alphabet[4]
Write a while loop that prints all the items in the list

count=0
while count < len(alphabet):
print alphabet[count]
count=count+1
Write a for-loop that prints all the items in the list

for x in alphabet
print x
Add the values ‘Q’ and ‘T’ to the list.
Alphabet.append('Q')
alphabet.append('T')
Write a loop that blanks out all the elements in the list to
‘-‘
for x in list:
x='-'
List1=[1 , 5, 4, 2, 0]
Write a while loop that subtracts 3 for each item in the list and update all the values with the new value
Count=0
while count<len(list1):
list1[count]=list1[count]-3
count=count+1
Write a For-loop that does the same thing as number 9 above.

for x in list1:
x=x-3
Write a while loop that adds numbers into an array until the user types -999
List=[]
print 'Enter a number to be added to the list'
num=int(raw_input())

while num!=-999:
list.append(num)
print 'Enter a number to be added to the list'
um=int(raw_input())