0% found this document useful (0 votes)
3 views2 pages

Assignment No. 01

This document outlines Assignment No. 1 for the CPE2133 course at Capital University, focusing on Python programming and data structures. It includes several questions related to control structures, short-circuit evaluation, flowchart design, variable naming rules, the modulo operator, and categorizing mixed data types. The assignment is due on April 14, 2025, and emphasizes original work without late submissions.

Uploaded by

nomiiking552527
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Assignment No. 01

This document outlines Assignment No. 1 for the CPE2133 course at Capital University, focusing on Python programming and data structures. It includes several questions related to control structures, short-circuit evaluation, flowchart design, variable naming rules, the modulo operator, and categorizing mixed data types. The assignment is due on April 14, 2025, and emphasizes original work without late submissions.

Uploaded by

nomiiking552527
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Capital University of Science and Technology

Department of Electrical and Computer Engineering


CPE2133: Data Structures and Algorithms, Spring-2025
Assignment No. 1

Instructor: Dr. Waseem Abbass Date: 06/04/2025


Total Marks: 10 Due Date: 14/04/2025
Instructions:
• Assignment submission should be on A4 size sheet.
• Late submission is not allowed.
• Copied Assignment will get zero credit.
• Avoid unnecessary details and arguments.

Name: _________________________ Reg. No. ______________________________

Python Programming and Data Structures

Question 1: Discuss in detail control structures in Python and their types.

Question 2: Explain the concept of short-circuit evaluation in Python control structures.


Write a Python function that demonstrates short-circuiting with both and and or operators
in a nested if-else structure. Discuss how this impacts program efficiency with an example.
Provide a screenshot of the output.

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).

Question 6: Write a Python program that performs the following:

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

You might also like