Student Activity

Student Activity Guide:

1) Conditional Statements (if, elif, else)

  • Create a program that takes user input and determines if a number is positive, negative, or zero.

Example Code:

num = int(input("Enter a number: "))
if num > 0:
    print("Positive number")
elif num < 0:
    print("Negative number")
else:
    print("Zero")

2) Looping Constructs (for, while)

  • Write a for loop that prints numbers from 1 to 10.

  • Implement a while loop that asks for user input until they enter "exit".

Example Code:

# For loop example
for i in range(1, 11):
    print(i)

# While loop example
while True:
    user_input = input("Type 'exit' to stop: ")
    if user_input.lower() == "exit":
        break

3) Iterators and range Function

  • Use range() to print even numbers from 2 to 20.

  • Iterate over a list using an iterator.

Example Code:

4) Nested Loops and Loop Control Statements (break, continue, pass)

  • Use a nested loop to print a pattern.

  • Demonstrate break, continue, and pass.

Example Code:

Student Exercises:

  1. Write a program that asks for a number and prints whether it is even or odd.

  2. Create a countdown timer using a while loop.

  3. Implement a function that prints numbers from 1 to 50 but skips numbers divisible by 5 using continue.

  4. Write a nested loop to generate a multiplication table from 1 to 10.

Last updated