Python, JS ve Go’da VE, VEYA ve DEĞİL Yaz
Senaryo
Aynı oda rezervasyon kuralını Python, JavaScript ve Go’da özdeş girdilerle karşılaştır.
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
}Sıra sende
Her durumu seç ve üç dilin de tamamen aynı boolean sonucu döndürdüğünü doğrula.
| Seçenek | Sonuç |
|---|---|
| freeSeats = 1, hasPermission = true (VE) | Sonucu görmek için yukarıdan bir seçenek tıkla. |
| freeSeats = 2, hasPermission = false (VE) | Sonucu görmek için yukarıdan bir seçenek tıkla. |
| isBlocked = false tersleme (DEĞİL) | Sonucu görmek için yukarıdan bir seçenek tıkla. |
Açıklamayı göster
- freeSeats = 1, hasPermission = true (VE)
Python: True | JS: true | Go: true. Yazım farklı, ortak kural aynı.
- freeSeats = 2, hasPermission = false (VE)
Python: False | JS: false | Go: false.
- isBlocked = false tersleme (DEĞİL)
Python: not is_blocked -> True | JS/Go: !isBlocked -> true.
Sözdizimi mantığı gizlemesin. Doğruluk tablon hazırsa sözcükler (and/or/not) ile simgeler (&&/||/!) arasında çeviri birebirdir.
Önce gözden geçir
Ortak test durumlarını indir
Sıra sende
"hasStudentCard VEYA hasGuestPass" kuralını Python, JavaScript ve Go’da yaz.
Sık yapılan hata Python’da && yazmak veya JS/Go’da çift yerine tek & kullanmak.
Çalışmanı kontrol et
Python: has_student_card or has_guest_pass; JS/Go: hasStudentCard || hasGuestPass.
Kısa kontrol
Tarayıcı ilerlemeni kaydedemedi. Değişiklikler bu sayfadan ayrılana kadar geçerli.