In: Computer Science
Write a Python program to read in the temperatures for ten consecutive days in Celsius and store them into an array. The entire array should then be displayed. Next each temperature in the array should be converted to Fahrenheit and the entire array should be again be displayed. The formula for converting Celsius to Fahrenheit is °F = (°C × 1.8) + 32. Finally, the number of cool, warm and hot days should be counted and the number of each type of days should be displayed. You should decide on the thresholds for determining whether a day is cool, warm or hot.
The above code is implemented in python
# Function to display the temperature stored in list
def display_temp(a,s):
j=1
for i in range(len(a)):
print("The temperature of day ",j," is",a[i],s)
j+=1
print()
# Function to convert celcius to Farenheit
def convert_farenheit(c):
return (c*1.8)+32
# Program starts here
print("Enter the temperature of 10 consective days in celcius")
arr = list(map(int,input().split())) # This is used to take space seperated input
display_temp(arr,"ᴼC") # display_temp function is called
# This loop is used to convert every element from celcius to farenheit
for i in range(len(arr)):
arr[i]=convert_farenheit(arr[i]) # conversion is done using convert_farenheit function defined above
display_temp(arr,"ᴼF") # array is displayed
# The temperature between 32 degree Farenheit to 92 degree Fareheiti is considered as cold
# The temperature between 93 degree Farenheit to 152 degree Fareheiti is considered as warm
#The temperature between 153 degree Farenheit to 212 degree Fareheiti is considered as hot
# Threshold can be different
cold=0
warm=0
hot=0
for i in arr:
if i>=32 and i<=92:
cold+=1
elif i>=93 and i<=152:
warm+=1
else:
hot+=1
print("Number of Cold Days is:",cold)
print("Number of Warm Days is:",warm)
print("Number of Hot Days is:",hot)
Output
Enter the temperature of 10 consective days in celcius
45 23 12 87 22 11 8 66 92 44
The temperature of day 1 is 45 ᴼC
The temperature of day 2 is 23 ᴼC
The temperature of day 3 is 12 ᴼC
The temperature of day 4 is 87 ᴼC
The temperature of day 5 is 22 ᴼC
The temperature of day 6 is 11 ᴼC
The temperature of day 7 is 8 ᴼC
The temperature of day 8 is 66 ᴼC
The temperature of day 9 is 92 ᴼC
The temperature of day 10 is 44 ᴼC
The temperature of day 1 is 113.0 ᴼF
The temperature of day 2 is 73.4 ᴼF
The temperature of day 3 is 53.6 ᴼF
The temperature of day 4 is 188.6 ᴼF
The temperature of day 5 is 71.6 ᴼF
The temperature of day 6 is 51.8 ᴼF
The temperature of day 7 is 46.4 ᴼF
The temperature of day 8 is 150.8 ᴼF
The temperature of day 9 is 197.6 ᴼF
The temperature of day 10 is 111.2 ᴼF
Number of Cold Days is: 5
Number of Warm Days is: 3
Number of Hot Days is: 2