IDLE
.
Kelvin = (Fahrenheit - 32) / 1.8 + 273.15
Fahrenheit = Kelvin * 9/5 - 459.67
def get_int(prompt):
input
to get a value
fahrenheit_to_kelvin_table(min, max):
def fahrenheit_to_kelvin(fahr):
def kelvin_to_fahrenheit_table(min, max):
def kelvin_to_fahrenheit(kelvin):
min_fahr = get_int("Minimum Fahrenheit: ") max_fahr = get_int("Maximum Fahrenheit: ") print() fahrenheit_to_kelvin_table(min_fahr, max_fahr) print() min_kelvin = get_int("Minimum Kelvin: ") max_kelvin = get_int("Maximum Kelvin: ") print() kelvin_to_fahrenheit_table(min_kelvin, max_kelvin)
Minimum Fahrenheit: 20 Maximum Fahrenheit: 30 Fahrenheit Kelvin ---------------------- 20 266 21 267 22 268 23 268 24 269 25 269 26 270 27 270 28 271 29 271 30 272 Minimum Kelvin: 260 Maximum Kelvin: 270 Kelvin Fahrenheit ---------------------- 260 8 261 10 262 12 263 14 264 16 265 17 266 19 267 21 268 23 269 25 270 26
pass
. input
to give the variable number a value. input
. pass
statement from
fahrenheit_to_kelvin_table. for
loop that gives the loop variable
fahr values from min
to max. range
to do this, and be careful
about the 2nd argument. print
statement in
fahrenheit_to_kelvin_table. pass
statement from
fahrenheit_to_kelvin. return
statement in
fahrenheit_to_kelvin. kelvin = (fahr - 32) / 1.8 + 273.15Turn the value of kelvin into an integer with an assignment statement using
round
. str
string conversion function on
both fahr and
kelvin. fahr = kelvin * 9/5 - 459.67
Minimum Fahrenheit: 20 Maximum Fahrenheit: 30 Fahrenheit Kelvin ---------------------- 20 266 21 267 22 268 23 268 24 269 25 269 26 270 27 270 28 271 29 271 30 272 Minimum Kelvin: 260 Maximum Kelvin: 270 Kelvin Fahrenheit ---------------------- 260 8 261 10 262 12 263 14 264 16 265 17 266 19 267 21 268 23 269 25 270 26
cd it116/hw/hw7
python3 hw7.py
Minimum Fahrenheit: 20 Maximum Fahrenheit: 30 Fahrenheit Kelvin ---------------------- 20 266 21 267 22 268 23 268 24 269 25 269 26 270 27 270 28 271 29 271 30 272 Minimum Kelvin: 260 Maximum Kelvin: 270 Kelvin Fahrenheit ---------------------- 260 8 261 10 262 12 263 14 264 16 265 17 266 19 267 21 268 23 269 25 270 26
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.