mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
61cb40734c
Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com>
1.7 KiB
1.7 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69cfca90e8a0a6d4d6871c51 | Challenge 267: Parsec Converter | 29 | challenge-267 |
--description--
In a distant galaxy, parsecs are used to measure both time and distance. Given an integer number of parsecs, return its equivalent in time or distance.
- If the given integer is odd, it represents time. If it's even, it represents distance.
Use these conversion rates:
| Parsecs | Time/Distance |
|---|---|
| 1 | 2 hours |
| 2 | 6 light years |
Return the converted value as an integer.
--hints--
convert_parsecs(1) should return 2.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_parsecs(1), 2)`)
}})
convert_parsecs(2) should return 6.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_parsecs(2), 6)`)
}})
convert_parsecs(31) should return 62.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_parsecs(31), 62)`)
}})
convert_parsecs(88) should return 264.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_parsecs(88), 264)`)
}})
convert_parsecs(17) should return 34.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_parsecs(17), 34)`)
}})
convert_parsecs(14) should return 42.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(convert_parsecs(14), 42)`)
}})
--seed--
--seed-contents--
def convert_parsecs(parsecs):
return parsecs
--solutions--
def convert_parsecs(parsecs):
if parsecs % 2 != 0:
return parsecs * 2
else:
return parsecs * 3