Conditionals and If Statements — Intro to Programming 練習ワークシート
A conditional lets a program make decisions. An if statement runs a block of code only when its condition is True; otherwise the block is skipped. This is how programs react differently to different inputs.
Conditions are Boolean expressions — they evaluate to True or False. Comparison operators produce Booleans: == (equal), != (not equal), < (less than), > (greater than), <= (less than or equal), >= (greater than or equal). Remember that == compares values while = assigns a value.
Boolean operators combine conditions: and is True only when both sides are True, or is True when at least one side is True, and not flips True to False. Parentheses can clarify the order of evaluation.
An if/elif/else chain checks conditions from top to bottom and runs only the first block whose condition is True. The else block is the catch-all that runs when no earlier condition matched. In Python, indentation defines which lines belong to each block.
練習するスキル
- Writing if, elif, and else statements
- Using comparison operators correctly
- Combining conditions with and, or, not
- Tracing code output through branches
- Distinguishing = (assignment) from == (comparison)
練習ワークシート:Conditionals and If Statements
指示: 各問題を丁寧に解きましょう。途中式もはっきりと書きましょう。最終的な答えは、指定された場所または指示に従って別の用紙に書いてください。
-
1.What is the purpose of an if statement in a program?
- A. To repeat a block of code multiple times
- B. To make a decision and execute code only when a condition is true
- C. To store multiple values in a single variable
- D. To display output to the user
Conditionals and If Statements — 練習ワークシート(続き)
-
2.In the following code snippet, what will be printed to the screen? x = 10 if x > 5: print("Large") else: print("Small")
Conditionals and If Statements — 練習ワークシート(続き)
-
3.Write an if statement that checks if a variable called age is greater than or equal to 18. If it is, print "Adult". Otherwise, print "Minor".
Conditionals and If Statements — 練習ワークシート(続き)
-
4.Which of the following is the correct syntax for an if-else statement in Python?
- A. if condition { } else { }
- B. if condition: // code else: // code
- C. if (condition) then { } else { }
- D. if condition then code else code
Conditionals and If Statements — 練習ワークシート(続き)
-
5.What is the output of the following code? num = 7 if num print("Even") else: print("Odd")
Conditionals and If Statements — 練習ワークシート(続き)
-
6.Write a program segment that assigns the string "Positive" to a variable called result if a number stored in n is greater than 0. If n is less than 0, assign "Negative". If n equals 0, assign "Zero".
Conditionals and If Statements — 練習ワークシート(続き)
-
7.What will the following code print? score = 75 if score >= 90: print("A") elif score >= 80: print("B") elif score >= 70: print("C") else: print("F")
- A. A
- B. B
- C. C
- D. F
Conditionals and If Statements — 練習ワークシート(続き)
-
8.Explain the difference between if and elif in a conditional statement.
-
9.Write a conditional statement that checks if a variable temp is greater than 100. If it is, print "Hot". If temp is between 50 and 100 (inclusive), print "Warm". Otherwise, print "Cold".
Conditionals and If Statements — 練習ワークシート(続き)
-
10.Which of the following conditions checks if x is NOT equal to 5?
- A. if x == 5:
- B. if x != 5:
- C. if x <> 5:
- D. if x =! 5:
解答集
-
1.
An if statement makes a decision and executes code only when a condition is true.最終回答: B
-
2.
Since x = 10 and 10 > 5 is true, the if branch executes and prints "Large".最終回答: Large
-
3.
最終回答: if age >= 18: print("Adult") else: print("Minor")
-
4.
In Python, an if statement uses a colon after the condition and indented code blocks.最終回答: B
-
5.
Since 7最終回答: Odd
解答集(続き)
-
6.
最終回答: if n > 0: result = "Positive" elif n < 0: result = "Negative" else: result = "Zero"
-
7.
Since 75 ≥ 70 is true and the earlier conditions (≥ 90, ≥ 80) are false, the elif score >= 70 branch executes and prints "C".最終回答: C
-
8.
最終回答: if checks a condition and executes its block if true. elif (short for "else if") is used after an if to check an additional condition only if the previous conditions were false. This allows multiple mutually exclusive conditions to be checked in sequence.
解答集(続き)
-
9.
最終回答: if temp > 100: print("Hot") elif temp >= 50: print("Warm") else: print("Cold")
-
10.
The != operator checks if two values are not equal in Python.最終回答: B
避けるべきよくある間違い
- Using = instead of == in a condition
- Forgetting the colon after if, elif, or else
- Incorrect indentation of the block body
- Assuming every elif runs instead of only the first True branch
- Mixing up and with or when combining conditions
自分だけのワークシートを作成
好きな難易度でconditionals and if statementsの問題を新しく作成したいですか?WorksheetSmithを使えば、印刷可能なカスタムPDFを数秒で作成できます。
最終更新:2026