Back to Freecodecamp

Challenge 176: Groundhog Day

curriculum/challenges/english/blocks/daily-coding-challenges-python/69738771fb5a7b8b24cca2a2.md

latest2.2 KB
Original Source

--description--

Today is Groundhog Day, in which a groundhog predicts the weather based on whether or not it sees its shadow.

Given a value representing the groundhog's appearance, return the correct prediction:

  • If the given value is the boolean true (the groundhog saw its shadow), return "Looks like we'll have six more weeks of winter.".
  • If the value is the boolean false (the groundhog did not see its shadow), return "It's going to be an early spring.".
  • If the value is anything else (the groundhog did not show up), return "No prediction this year.".

--hints--

groundhog_day_prediction(True) should return "Looks like we'll have six more weeks of winter.".

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(groundhog_day_prediction(True), "Looks like we'll have six more weeks of winter.")`)
}})

groundhog_day_prediction(False) should return "It's going to be an early spring.".

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(groundhog_day_prediction(False), "It's going to be an early spring.")`)
}})

groundhog_day_prediction(None) should return "No prediction this year.".

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(groundhog_day_prediction(None), "No prediction this year.")`)
}})

groundhog_day_prediction(" ") should return "No prediction this year.".

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(groundhog_day_prediction(" "), "No prediction this year.")`)
}})

groundhog_day_prediction("True") should return "No prediction this year.".

js
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(groundhog_day_prediction("True"), "No prediction this year.")`)
}})

--seed--

--seed-contents--

py
def groundhog_day_prediction(appearance):

    return appearance

--solutions--

py
def groundhog_day_prediction(appearance):
    if appearance is True:
        return "Looks like we'll have six more weeks of winter."
    if appearance is False:
        return "It's going to be an early spring."
    return "No prediction this year."