IDLE
.
def get_int(prompt):
input
to get a value
def inches_to_centimeters_table(min, max):
def inches_to_centimeters(inches):
def centimeters_to_inches_table(min, max):
def centimeters_to_inches(centimeters):
min_inches = get_int("Minimum inches: ") max_inches = get_int("Maximum inches: ") print() inches_to_centimeters_table(min_inches, max_inches) print() min_centimeters = get_int("Minimum centimeters: ") max_centimeters = get_int("Maximum centimeters: ") print() centimeters_to_inches_table(min_centimeters, max_centimeters
Minimum inches: 1 Maximum inches: 10 Inches Centimeters ------------------- 1 3 2 5 3 8 4 10 5 13 6 15 7 18 8 20 9 23 10 25 Minimum centimeters: 1 Maximum centimeters: 10 Centimeters Inches ------------------ 1 0 2 1 3 1 4 2 5 2 6 2 7 3 8 3 9 4 10 4
pass
. pass
statement from get_int. input
to give the variable number a value. input
. pass
statement from
inches_to_centimeters_table. for
loop that gives the loop variable
inches values from min
to max. range
to do this, and be careful
about the 2nd argument. print
statement in
inches_to_centimeters_table. pass
statement from
inches_to_centimeters. return
statement in
inches_to_centimeters. cm = inches * 2.54Turn the value of cm into an integer with an assignment statement using
round
. str
string conversion function on
both inches and
cm. inches = centimeters * 0.39370079
Minimum inches: 1 Maximum inches: 10 Inches Centimeters ------------------- 1 3 2 5 3 8 4 10 5 13 6 15 7 18 8 20 9 23 10 25 Minimum centimeters: 1 Maximum centimeters: 10 Centimeters Inches ------------------ 1 0 2 1 3 1 4 2 5 2 6 2 7 3 8 3 9 4 10 4The entries in blue are user input.
cd it116/hw/hw7
python3 hw7.py
Minimum inches: 1 Maximum inches: 10 Inches Centimeters ------------------- 1 3 2 5 3 8 4 10 5 13 6 15 7 18 8 20 9 23 10 25 Minimum centimeters: 1 Maximum centimeters: 10 Centimeters Inches ------------------ 1 0 2 1 3 1 4 2 5 2 6 2 7 3 8 3 9 4 10 4
Copyright © 2020 Glenn Hoffman. All rights reserved. May not be reproduced without permission.