def scale(factor, lst):
'''
Purpose: Scale the elements of lst by a constant factor.
Pre: factor is a number. lst is a list of numbers.
Post: Mutates lst by multiplying each element by factor.
Returns nothing.
'''
# We need the index, not just the value, so we can assign
# to lst[i].
for i in range(len(lst)):
lst[i] *= factor
# Return nothing (could just omit this line)
return
def main():
numbers = [ 11, 16, 20, 3, 99 ]
print("Before scaling:")
for n in numbers:
print(n, end=" ")
print() # end the line
factor = float(input("Enter a scaling factor: "))
scale(factor, numbers)
# That call modified the 'numbers' list!
print("After scaling:")
for n in numbers:
print(n, end=" ")
print() # end the line
main()