The goal is to rewrite the following program without using any for loops. The mo
ID: 3603047 • Letter: T
Question
The goal is to rewrite the following program without using any for loops. The motivation behind this lab is to help you understand what a for loop actually does. The program output is expecting you to have entered the following ten numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
def double(integerList):
doubledList = []
for integer in integerList:
doubledList.append(integer*2)
return doubledList
def printList(myList):
for item in myList:
print(item)
return
def main():
numList = []
for j in range(10):
num = int(input("Please enter a whole number: "))
numList.append(num)
numList = double(numList)
print('The list doubled is printed below: ')
printList(numList)
return
main()
Explanation / Answer
def double(integerList):
doubledList = []
count = 0
while count < len(integerList):
integer = integerList[count]
doubledList.append(integer*2)
count = count + 1
return doubledList
def printList(myList):
count = 0
while count < len(myList):
item = myList[count]
print(item)
count = count + 1
return
def main():
numList = []
j = 0
while j < 10:
num = int(input("Please enter a whole number: "))
numList.append(num)
j = j + 1
numList = double(numList)
print('The list doubled is printed below: ')
printList(numList)
return
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.