Hack 1: Odd or Even Checker
Description: This hack checks if a given number is odd or even.
- Define a function named
check_odd_eventhat takes one parameter:number. - Use an
ifstatement to check if the number is divisible by 2. - Return
"Even"if true; otherwise, return"Odd".
Call the function with different numbers to test your work.
Hack 2: Leap Year Checker
Description: This hack determines if a given year is a leap year.
- Define a function named
is_leap_yearthat takes one parameter:year. - Use an
ifstatement to check if the year is divisible by 4 but not by 100, or divisible by 400. - Return
"Leap Year"if true; otherwise, return"Not a Leap Year".
Call the function with different years to test your work.
Hack 3: Temperature Range Checker
Description: This hack checks if a given temperature is considered cold, warm, or hot.
- Define a function named
temperature_rangethat takes one parameter:temperature. - Use
if...elif...elsestatements to categorize the temperature:- Return
"Cold"for temperatures below 60°F. - Return
"Warm"for temperatures between 60°F and 80°F. - Return
"Hot"for temperatures above 85°F.
- Return
Call the function with different temperature values to check your work.