Skip to content

Commit 103476d

Browse files
authored
Merge pull request #711 from codewithdhruba01/doc/questionset
Add Practice Questions to Conditional Statements in Python Documentation
2 parents 063f71f + 3204f2e commit 103476d

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

docs/python/conditional-statements-python.md

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,75 @@ print("Outside if block")
163163
| Nested `if` | `if` inside another `if` |
164164
| Ternary Expression | Short form of `if...else` |
165165

166-
---
166+
167+
### **Practice Questions**
168+
169+
#### 1. **Positive / Negative / Zero Checker**
170+
171+
Write a Python program that takes a number as input and checks whether it is **positive**, **negative**, or **zero**.
172+
173+
174+
#### 2. **Odd or Even**
175+
176+
Write a Python program to check whether a number is **even** or **odd**.
177+
178+
179+
#### 3. **Age Eligibility for Voting**
180+
181+
Write a program to take a person’s age as input and check if they are **eligible to vote** (18 years or older).
182+
183+
184+
#### 4. **Largest of Two Numbers**
185+
186+
Write a Python program that takes two numbers as input and prints the **larger number** using conditional statements.
187+
188+
189+
#### 5. **Largest of Three Numbers**
190+
191+
Write a Python program to find the **largest among three numbers** entered by the user using `if`, `elif`, and `else`.
192+
193+
194+
#### 6. **Grading System**
195+
196+
Write a Python program to take a student's marks as input and print the **grade** according to the following criteria:
197+
198+
* Marks ≥ 90 → Grade A
199+
* Marks ≥ 75 and < 90 → Grade B
200+
* Marks ≥ 50 and < 75 → Grade C
201+
* Marks < 50 → Grade F
202+
203+
204+
#### 7. **Leap Year Checker**
205+
206+
Write a program to check whether a given year is a **leap year** or not.
207+
*(Hint: A year is leap if divisible by 4 but not 100, or divisible by 400)*
208+
209+
210+
#### 8. **Nested If — Number Range Checker**
211+
212+
Write a program that takes a number as input and:
213+
214+
* Checks if it's **positive**.
215+
* If positive, further checks if it is **less than 10**, **between 10 and 50**, or **greater than 50**.
216+
217+
218+
#### 9. **Character Classification**
219+
220+
Write a program to input a single character and check whether it is:
221+
222+
* a **vowel**,
223+
* a **consonant**,
224+
* a **digit**, or
225+
* a **special character**.
226+
227+
228+
#### 10. **Login Authentication (Simple)**
229+
230+
Write a program that asks the user to enter a **username** and **password**.
231+
232+
* If the username is `"admin"` and the password is `"12345"`, print **“Login Successful”**.
233+
* Otherwise, print **“Invalid credentials”**.
234+
167235

168236
## Conclusion
169237

0 commit comments

Comments
 (0)