Skip to content · ⁨ข้ามไปยังเนื้อหา⁩

Even or odd · ⁨คู่หรือคี่⁩

English

Even or odd

n is 7. Print even when n divides by 2 with no remainder, and odd otherwise.

% gives the remainder. 7 % 2 is 1, 8 % 2 is 0. Compare it with == (two equals signs) — one equals sign means store a value, and Python will tell you so.

ไทย

คู่หรือคี่

n คือ 7. ให้พิมพ์ even เมื่อ n หารด้วย 2 ลงตัว (เศษเป็นศูนย์) และพิมพ์ odd ในกรณีอื่น ๆ

% ใช้คำนวณหา เศษเหลือ. ตัวแปร 7 % 2 มีค่าเท่ากับ 1, และ 8 % 2 มีค่าเท่ากับ 0. ให้เปรียบเทียบมันกับ == โดยใช้เครื่องหมายเท่ากับสองตัว (==) — เครื่องหมายเท่ากับหนึ่งตัว (=) หมายความว่า การเก็บค่า และ Python จะบอกคุณเมื่อทำผิด

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP