الاختيار
تحتاج هذه الصفحة إلى متصفح حديث (يدعم SharedArrayBuffer). يرجى تحديث Chrome أو Edge أو Firefox أو Safari إلى أحدث إصدار.
English
Programs make choices
- Selection means the program picks what to do based on a condition.
- A condition is a question that is
TrueorFalse. - This is a key idea in AP CSP: code that decides.
English
if / elif / else
ifruns its block only when the condition isTrue.elif("else if") checks another condition if the ones above wereFalse.elseruns when none of the conditions wereTrue.

English
hour = 14
if hour < 12:
print("Morning")
elif hour < 18:
print("Afternoon")
else:
print("Evening")
English
Comparisons make conditions
==equal,!=not equal,<><=>=.==tests if two values are equal; a single=stores a value.- The result of a comparison is
TrueorFalse.
English
score = 72
print(score >= 50)
print(score == 100)
English
Boolean logic: and / or / not
andisTrueonly when both sides areTrue.orisTruewhen at least one side isTrue.notflips it:not TrueisFalse.
English
age = 16
if age >= 13 and age <= 19:
print("Teenager")
else:
print("Not a teenager")
English
In AP CSP pseudocode
- Python
if/elsematches CB'sIF(condition){ } ELSE { }. - CB uses words for logic:
AND,OR,NOT. DISPLAY= print,←==.
IF (score >= 50)
{
DISPLAY("Pass")
}
ELSE
{
DISPLAY("Fail")
}
IF ((age >= 13) AND (age <= 19))
{
DISPLAY("Teenager")
}
English
Common mistakes
- Compare with
==, not=. - Indent the block that runs when the condition is true.
English
Now you try
- Read each task to see what to print or check.
- Match the output text exactly.
استكشف
Selection picks a branch
Conditions are tested in order; the first true one runs.
الصعوبة 2/5 · 140 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Read a score with int(input()). Print A if it is 80 or more, B if it is 60 or more, otherwise C. Use if / elif / else. For input 75, print B.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 2/5 · 140 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
temp هي 22. Set comfortable إلى True when temp is from 18 إلى 25 (inclusive), else False. Use one comparison with and.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 2/5 · 140 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
day هي "Sun" و is_holiday هي False. Print Day off if it is a weekend ("Sat" أو "Sun") أو a holiday; otherwise print Work day. Use or.
اضغط تشغيل لرؤية المخرجات هنا.