From da8c8bfc465af58ed89d8dd84bce0a160450c57f Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 19:17:37 +0000 Subject: [PATCH 1/3] Setting up GitHub Classroom Feedback From efea3ffdf6d348a39a3f594ed955061ff440fc41 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 19:17:41 +0000 Subject: [PATCH 2/3] add deadline --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ce9d6ee..41797a7 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/wXQiiW8O) # Lab3 \ No newline at end of file From f51ffb1d735c83e938f65b4c2deaf303c237ae19 Mon Sep 17 00:00:00 2001 From: rishit-0 Date: Thu, 23 Apr 2026 18:23:48 -0700 Subject: [PATCH 3/3] Lab 3 --- Task_1.py | 22 ++++++++++++++++++++++ Task_2.py | 20 ++++++++++++++++++++ functions.py | 2 +- testcases.py | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Task_1.py create mode 100644 Task_2.py diff --git a/Task_1.py b/Task_1.py new file mode 100644 index 0000000..0d32d62 --- /dev/null +++ b/Task_1.py @@ -0,0 +1,22 @@ +more = [x + 1 for x in [1,2,3,4]] # List, in order, the values that x takes at each step. +print() # more=[2,3,4,5] + + +def square(n:int) -> int: + return n * n # Call 1: n=1, returns 1. Call 2: n=2, returns 4. Call 3: n=3, returns 9. Call 4: n=4, returns 16 +squares = [square(x) for x in [1,2,3,4]] # Squares is a list of the return values for each call of the function +print() + + +def check(n:int) -> bool: + return n > 2 # Call 1: n=0, returns False. Call 2: n=1, returns False. Call 3: n=2, returns False. Call 4: n=3, returns True. Call 5: n=4, returns True +answer = [x for x in range(5) if check(x)] # answer=[3,4] +print() + + +def inc(m:int) -> int: + return m + 1 # Call 1: m=3, returns 4. Call 2: m=4, returns 5. +def check(n:int) -> bool: + return n > 2 # Call 1: n=0, returns False. Call 2: n=1, returns False. Call 3: n=2, returns False. Call 4: n=3, returns True. Call 5: n=4, returns True +answer = [inc(x) for x in range(5) if check(x)] # answer=[4,5] +print() diff --git a/Task_2.py b/Task_2.py new file mode 100644 index 0000000..5ac06de --- /dev/null +++ b/Task_2.py @@ -0,0 +1,20 @@ +def tally(nums:list[int]) -> int: + total = 0 + for num in nums: + total = total + num # 1: num=4, total=4. 2: num=9, total=13. 3: num=2, total=15. 4: num=1, total=16 + return total +result = tally([4, 9, 2, 1]) + +def copy(nums:list[int]) -> list[int]: + new_list = [] + for idx in range(len(nums)): + new_list.append(nums[idx]) # 1: idx=0, new_list=[4]. 2: idx=1, new_list=[4,9]. 3: idx=2, new_list=[4,9,2]. 4: idx=3, new_list=[4,9,2,1] + return new_list # This loop indexes the input list and makes a new list with all the same numbers in the same place +result = copy([4, 9, 2, 1]) + +def increment_all(nums:list[int]) -> list[int]: + new_list = [] + for value in nums: + new_list.append(value + 1) # 1: value=4, new_list=[5]. 2: value=9, new_list=[5,10]. 3: value=2, new_list=[5,10,3]. 4: value=1, new_list=[5,10,3,2] + return new_list +result = increment_all([4, 9, 2, 1]) \ No newline at end of file diff --git a/functions.py b/functions.py index a15fca4..06363f1 100644 --- a/functions.py +++ b/functions.py @@ -2,5 +2,5 @@ # Input: a number to be doubled # Result: a number def double(n:int) -> int: - result = n * n + result = 2 * n return result diff --git a/testcases.py b/testcases.py index 3ebd851..5a964e1 100644 --- a/testcases.py +++ b/testcases.py @@ -15,3 +15,6 @@ def test_double_two(self): if __name__ == '__main__': unittest.main() + +# test_double_one giving the right answer doesn't imply that the double function is correct. +# For the value of 2, 2*2=2**2, so it outputs the expected value even if the code is fundamentally incorrect.