Even or odd · คู่หรือคี่
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 จะบอกคุณเมื่อทำผิด
n is 7. Print even when n divides by 2 with no remainder, and odd otherwise. · n คือ 7. ให้พิมพ์ even เมื่อ n หารด้วย 2 ลงตัว (เศษเป็นศูนย์) และพิมพ์ odd ในกรณีอื่น ๆ
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่