Basic If Statement:
Write a short Python snippet using an if statement to check whether a variable (choose any name and number) is positive. If it is, print "Positive"; otherwise, print "Not positive."
Hint: Use an if-else structure to handle both cases.
Simple For Loop with Range:
Write a Python code snippet that uses a for loop with the range() function to print the numbers 0 to 4. Next, modify the loop to only print odd numbers by incorporating the continue statement.
While Loop Fundamentals:
Write a Python while loop that prints "Hello" exactly three times. Explain briefly what condition controls your loop termination.
Even/Odd Checker:
Write a Python script that asks the user for an integer and then prints whether the number is even or odd. Use conditional statements (if-else) and include code to convert the user’s input (initially a string) into an integer.
Explain how the conversion and decision-making process works in your code.
Nested Loop – Vowel Counter:
Create a Python program that uses nested loops to process a list of strings. For each string, iterate over its characters and count the vowels (a, e, i, o, u). Print each string along with its vowel count.
In your answer, describe your approach and why nested loops are useful for this task.
For Loop with Else Clause:
Write a Python for loop that iterates over a list of numbers. If it finds a number divisible by 7, it should immediately break out of the loop. If the loop completes without finding such a number, use the else clause to print "No multiples of 7 were found."
Explain how the else clause in a loop works in this context.
Pattern Generation with Nested Loops:
Write a Python program using nested loops and conditional statements that generates a pattern (e.g., a triangle of stars) based on an input value N from the user.
break, continue, and, where appropriate, an else clause with a loop.Break vs. Continue – Comparative Analysis:
Provide a written explanation (200–300 words) that discusses how the break and continue statements can alter the flow of a loop. Include specific code examples that demonstrate scenarios where each statement is advantageous.
for loop:
continue statement to skip processing it.break statement to exit the loop immediately.if-elif-else ladder and print an appropriate message.break), use an else clause after the loop to print a message indicating successful completion.while loop to ask the user if they want to input another list, allowing multiple rounds of processing until the user chooses to exit.