Reputation: 35
I'm so close to figuring this thing out, but I must be looking right past the solution. This program is meant to receive temperature values in Celsius, convert them to Fahrenheit, and then count the number of "cool", "warm", and "hot" days. I've got the first two parts of this problem figured out, but for whatever reason, my program isn't counting the number of each kind of day correctly.
temperature_list = []
value = int(input("Number of temperatures to enter: "))
for i in range(value):
#We now collect the values
t = int(input("Enter temperature: "))
temperature_list.append(t)
print("Your entered temperatures in Celsius are: ", temperature_list)
#Next up is to print those temperatures in Fahrenheit, which we'll do in a batch
f_list = list()
f = [t*1.8 + 32 for t in temperature_list]
f_list.append(f)
fint = int(f[0])
cooldays = 0
hotdays = 0
for f in f_list:
if fint > 65 :
cooldays = cooldays + 1
if fint < 80 :
hotdays = hotdays + 1
print("Your temperature in Fahrenheit is: ", f[:])
warmdays = (len(f_list) - (cooldays + hotdays))
print(cooldays)
print(hotdays)
print(warmdays)
Can someone tell me what I'm missing, here?
Upvotes: 2
Views: 293
Reputation: 1301
Currently, you are checking fint with the threshold value for every iteration. Instead you want to check it against each value in f_list
.
Secondly, depending on your requirements, you also probably need to change your conditions. Like for example 66 is greater than 65 and also less than 80. So it will increment both... Please revise your conditions.
Third,f = [t*1.8 + 32 for t in temperature_list]
makes f
a list of floats. You append this to another list, f_list
. Essentially, your f_list is now a 2D matrix. For example: [[65,66,68.2, 98.3]]
Note the double square braces...
You could just assign the temperatures directly to f_list
, instead of creating an intermediate variable f
f_list = [t*1.8 + 32 for t in temperature_list]
for f in f_list:
if f < 65 :
cooldays = cooldays + 1
elif f > 80 :
hotdays = hotdays + 1
Upvotes: 3