Problème
Afficher la traductionWhole numbers divisible by 2 are even; other whole numbers are odd. A number with a fractional part is neither. Zero is even, and negative integers follow the same rule.
Implement number_parity(number).
Input
number: The number to classify.
Output
Return odd, even, or neither as lowercase text.
Contraintes
−1,000,000 ≤ number ≤ 1,000,000. The input is finite and has at most two decimal places.
Exemples
Entrée :
number = 14
Sortie attendue :
expected = "even"
Entrée :
double number = 14;
Sortie attendue :
std::string expected = "even";
Entrée :
double number = 14;
Sortie attendue :
string expected = "even";
Explication
14 = 2 × 7, so it is divisible by 2.
Entrée :
number = 3.5
Sortie attendue :
expected = "neither"
Entrée :
double number = 3.5;
Sortie attendue :
std::string expected = "neither";
Entrée :
double number = 3.5;
Sortie attendue :
string expected = "neither";
Explication
3.5 has a fractional part, so it is neither an odd nor an even integer.
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.