IDLE.
def div_three_list_create(min, max, length):
create an empty list
for i running from 0 to length:
create a random integer using random.randint
if the number is evenly divisible by three:
append it to the list
return the list
def odds_count(list):
set the variable odd_count to 0
for each number in the list:
if the number is odd:
increment odd_count
return odd_count
def triple_list(list):
for each number in the list:
multiply the value of the element by three
def max_min_list(list):
sort the list
return the last and first number in the list
random.seed(97) div_three_list_create(25, 100, 15) num_list = div_three_list_create(25, 100, 15) print(num_list) odds_count(num_list) print(odds_count(num_list)) triple_list(num_list) print(num_list) max_min_list(num_list) max, min = max_min_list(num_list) print(max, min)
[60, 48, 27, 99, 90, 27, 96, 81, 30, 93, 93, 96, 81, 51, 48] 8 [180, 144, 81, 297, 270, 81, 288, 243, 90, 279, 279, 288, 243, 153, 144] 297 81
pass. pass statement from
div_three_list_create. while loops that keeps running as long
as the length of the list is less than
length. randint. print and append statements. if statement that runs if
num is evenly divisible by 3. print statement. for loop, return the list. pass statement from
odds_count. for loop over list. print statement. if statement that runs if
num is odd. if statement print
num. print statement. for loop return
odds_count. pass statement from
triple_list. for loop that creates indexes for each
entry in the loop. print statement. pass statement from
max_min_list. print statement. cd it116/hw/hw11
./hw11.py
[60, 48, 27, 99, 90, 27, 96, 81, 30, 93, 93, 96, 81, 51, 48] 8 [180, 144, 81, 297, 270, 81, 288, 243, 90, 279, 279, 288, 243, 153, 144] 297 81
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.