Answer: Code
Step-by-step explanation:
#add_hot_cold function
def add_hot_cold(obs):
"""
takes a string of observations as input
and returns the number of hot days minus
the number of cold days.
>>> add_hot_cold("CHCC")
-2
>>> add_hot_cold("HHHHHCCCHCHHHCHCHC")
4
>>>
"""
#set nday to 0
nday = 0
#process each letter in the string
for char in obs:
#if it is a hot day, add 1
if char == "H":
nday = nday + 1
#if it is a cold day, add -1
elif char == "C":
nday = nday - 1
#return nday
return nday
#Call the function on the string "HHHHHCCCHCHHHCHCHC" and print the result
print(add_hot_cold("HHHHHCCCHCHHHCHCHC"))
Note - The above code might not be indented. Please indent your code according to the below screenshot.
Sample Output:
Code Screenshot: