The main topics on this worksheets are variables, the built-in types int, float, and string, and the use of booleans and conditionals.
Collaboration on worksheets is strongly encouraged.
The main course materials to refer to for this worksheet are:
(Lecture videos are not linked on worksheets, but are also useful to review while working on worksheets. Video links can be found in the course course Blackboard site.)
Hot and humid air often feels hotter than hot dry air, in part due to slower evaporation of perspiration.
For this reason it can be helpful to describe weather conditions in terms of a heat index, a number which attempts to capture the "perceived temperature" by incorporating both the air temperature and relative humidity.
There are several heat indices that are in common use, and in this problem we'll look at one of them. The formula for it is described in https://www.weather.gov/media/ffc/ta_htindx.PDF, and adapted below.
Write a Python script called heatindex.py
that asks the user for the temperature in degrees Fahrenheit and the relative humidity percentage (as two separate input events). The script should then print the heat index. Specifically, running python heatindex.py
should result in prompts and output like the following:
Enter temperature (degrees F): 92
Enter relative humidity (percent): 60
The heat index is: 104.68441864000005
(Note that you are not supposed to write a program that uses fixed numbers like 92 and 70 for the temperature and humidity, though that would be a reasonable start. A completed program is supposed to accept whatever numbers the user types and do the calculation with those values.
Suppose you like numbers that are even (like 2, 16, and 44) and you also like numbers that are divisible by 5 (like 15, 65, and 2005). Naturally, you love numbers that are both even and divisible by 5 (like 260 and 1980).
Write a Python script intlike.py
that asks the user to enter a number, and then prints a message describing how much you like that number (specifically, printing "it's ok", "I like it", "I LOVE IT").
Here are some test cases. The first line is the number you type, and the second is the expected output.
5
I like it
28
I like it
0
I LOVE IT
77810
I LOVE IT
57
It's ok
2021
It's ok
You are probably familiar with two temperature scales: Fahrenheit (F) and Celsius (C).
There is a third temperature scale that is preferred in many scientific disciplines, the Kelvin scale (K), which has the advantage that 0K corresponds to absolute zero, the minimum temperature that is possible.
The formula to convert from Fahrenheit to Kelvin is: $$ T_{Kelvin} = \frac{5}{9}(T_{Fahrenheit} + 459.67) $$ The formula to convert from Celsius to Kelvin is: $$ T_{Kelvin} = T_{Celsius} + 273.15$$
Write a Python script kelvinator.py
that asks the user for a numeric temperature, and which then asks the user whether the temperature was given in Celsius, Fahrenheit, or Kelvin (which the user indicates by entering C, F, or K, respectively). The script should then convert the given temperature to Kelvin and print the result.
Here are some samples of input and expected output.
Enter numeric temperature: 91
Which scale is that measured in? (C=celsius, F=Fahrenheit, K=Kelvin) F
The corresponding Kelvin temperature is 305.9277777777778K
Enter numeric temperature: 40
Which scale is that measured in? (C=celsius, F=Fahrenheit, K=Kelvin) C
The corresponding Kelvin temperature is 313.15K
Enter numeric temperature: 500
Which scale is that measured in? (C=celsius, F=Fahrenheit, K=Kelvin) K
The corresponding Kelvin temperature is 500.0K
Here are suggestions for things to work on if you complete problems 1--3 in lab and have extra time. Solutions won't be given for these problems.
Make it so the temperature converter will let the user enter any one of "C", "c", "celsius", or "Celsius" to specify the Celsius scale, and similarly for the other scales.
Temperatures that are negative on the Kelvin scale do not exist. Make the temperature converter check the Kelvin temperature before printing, and make sure it is nonnegative. If it is negative, print an error message instead of the temperature, e.g. "Temperature is invalid!".