Assignment No. 01
Assignment No. 01
Question 3: Design and draw a flowchart for a program that determines if a given year is
a leap year using nested conditions. Then, implement this logic in Python using a
combination of if-elif-else and nested if statements. Test your code with the years 2024,
2025, and 1900, and attach screenshots of the output.
Question 4: The Python interpreter has strict rules for variable names. Which of the
following are legal Python names? If the name is not legal, state the reason.
1. and
2. _and
3. var
4. var1
5. 1var
6. my-name
7. your_name
8. your name
Question 4: Write down the type of the values stored in each of the variables below.
Attach Shell Screenshots.
1. x = False
2. y = 3.7
3. z = ‘Alex’
Page 1 of 2
4. xx = 7
5. yy = ‘True’
6. zz = 17
Question 5: The modulo operator (%) in Python can behave unexpectedly with negative
numbers and floating-point values. Write a Python function that:
Takes two inputs: a dividend and a divisor (both can be positive/negative integers or
floats).
Computes the modulo result and explains (via comments) why Python’s result might differ
from mathematical expectations.
Tests the function with the following pairs: (-10, 3), (10, -3), (-10, -3), (5.7, 2).
1. Takes a list of mixed data types (e.g., [5, "hello", 3.14, True, -9]) as input.
2. Uses a loop and control structures to categorize each element into separate lists
based on its type (int, float, str, bool).
3. Handles potential type errors gracefully using try-except.
4. Prints the categorized lists and their lengths.
Page 2 of 2