Write AND, OR, and NOT Across Python, JS, and Go
Scenario
Compare the exact same room-booking rule in Python, JavaScript, and Go on identical inputs.
def can_book_room(free_seats: int, has_permission: bool) -> bool:
return free_seats > 0 and has_permissionexport function canBookRoom(freeSeats, hasPermission) {
return freeSeats > 0 && hasPermission;
}func canBookRoom(freeSeats int, hasPermission bool) bool {
return freeSeats > 0 && hasPermission
}Try it yourself
Select each case and verify that all three languages return the exact same boolean.
| Case | Result |
|---|---|
| freeSeats = 1, hasPermission = true (AND) | Select a choice above to see what happens. |
| freeSeats = 2, hasPermission = false (AND) | Select a choice above to see what happens. |
| Negating isBlocked = false (NOT) | Select a choice above to see what happens. |
Reveal the explanation
- freeSeats = 1, hasPermission = true (AND)
Python: True | JS: true | Go: true. Different spelling, identical contract.
- freeSeats = 2, hasPermission = false (AND)
Python: False | JS: false | Go: false.
- Negating isBlocked = false (NOT)
Python: not is_blocked -> True | JS/Go: !isBlocked -> true.
Never let operator syntax hide the logic. Once your truth table is verified, translating between words (and/or/not) and symbols (&&/||/!) is mechanical.
Review first
Download shared test cases
Your turn
Write "hasStudentCard OR hasGuestPass" in Python, JavaScript, and Go.
Common mistake Writing && in Python or using a single & instead of && in JavaScript/Go.
Check your work
Python: has_student_card or has_guest_pass; JS/Go: hasStudentCard || hasGuestPass.
Quick check
This browser could not save your progress. Changes last until you leave the page.