IDLE.
def div_three_list_create(min, max, length):
create the empty list list
for i running from 0 to length of list:
create a random integer num using random.randint()
if num is evenly divisible by three:
append num to list
return list
def odds_count(list):
set odd_count to 0
for each number in list:
if number is odd:
add 1 to odd_count
return odd_count
def triple_list(list):
for index runing from 0 to the length of list:
set the variable number to the entry in list with position index
give number a new value by multiplying it by 3
use this new value of number to replace the entry in list specified by index
def max_min_list(list):
sort list
set first to the first value in list using an index
set last to the last value in list using an index
return first and last
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.