bignums.py
= [5, 7, 34, 5, 3, 545]
my_list
= []
big_numbers for num in my_list:
if num > 10:
big_numbers.append(num)
print(big_numbers)
Starting from the initial code:
bignums.py
= [5, 7, 34, 5, 3, 545]
my_list
= []
big_numbers for num in my_list:
if num > 10:
big_numbers.append(num)
print(big_numbers)
python bignums.py
[34, 545]
We pull out the middle four lines, indent them, put def big(numbers):
in front and add return big_numbers
to the end, paying careful attention to the indentation of the return
statement. Finally, we update the variable name used in the function to match the argument name numbers
:
bignums.py
def big(numbers):
= []
big_numbers for num in numbers:
if num > 10:
big_numbers.append(num)return big_numbers
= [5, 7, 34, 5, 3, 545]
my_list
= big(my_list)
large_numbers
print(large_numbers)
Terminal/Command Prompt
python bignums.py
[34, 545]