From d0ffbc58d3a894eb635006ce2323795f246d9976 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Tue, 7 Jan 2025 21:36:07 +0530 Subject: [PATCH 01/43] Update README.md explanation --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 53c5b27..3d1e383 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# python-programming-questions \ No newline at end of file +# python-programming-questions\ +The 4 Programming Questions evaluate correctly in my local system:\ +![image](https://github.com/user-attachments/assets/74b68136-80fd-4f3a-b984-bb9c4d5be0ac) + +The type of each question is given below:\ +1. **Data types** - basic operations on datatypes *(str -> f-string, title(), list->indexing, int-> //, %)* and not used loops. input outputs are handled by a driver code.\ +2. **Data Processing** - basic data processing patterns like *mapping, filtering*. input handled by driver code\ +3. **Data Processing I/O** - inputs from the stdin and print the output to stdout in the specified format (list of dictionaries).\ +4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly)\ From 75c1d60ee17ecd53f7a3732c801a77281c982fce Mon Sep 17 00:00:00 2001 From: YashviUp Date: Tue, 7 Jan 2025 21:36:46 +0530 Subject: [PATCH 02/43] Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3d1e383..2eda1fc 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# python-programming-questions\ +# python-programming-questions The 4 Programming Questions evaluate correctly in my local system:\ ![image](https://github.com/user-attachments/assets/74b68136-80fd-4f3a-b984-bb9c4d5be0ac) -The type of each question is given below:\ -1. **Data types** - basic operations on datatypes *(str -> f-string, title(), list->indexing, int-> //, %)* and not used loops. input outputs are handled by a driver code.\ -2. **Data Processing** - basic data processing patterns like *mapping, filtering*. input handled by driver code\ -3. **Data Processing I/O** - inputs from the stdin and print the output to stdout in the specified format (list of dictionaries).\ -4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly)\ +The type of each question is given below: +1. **Data types** - basic operations on datatypes *(str -> f-string, title(), list->indexing, int-> //, %)* and not used loops. input outputs are handled by a driver code. +2. **Data Processing** - basic data processing patterns like *mapping, filtering*. input handled by driver code +3. **Data Processing I/O** - inputs from the stdin and print the output to stdout in the specified format (list of dictionaries). +4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly) From 822cb844bd4c90072848458fb1f082c10da30445 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Tue, 7 Jan 2025 21:41:50 +0530 Subject: [PATCH 03/43] Create Q1_price_into_rupees.md 1. Data types - basic operations on datatypes (str -> f-string, title(), list->indexing, int-> //, %) and not used loops. input outputs are handled by a driver code. --- Programming Ques/Q1_price_into_rupees.md | 199 +++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 Programming Ques/Q1_price_into_rupees.md diff --git a/Programming Ques/Q1_price_into_rupees.md b/Programming Ques/Q1_price_into_rupees.md new file mode 100644 index 0000000..b1833b8 --- /dev/null +++ b/Programming Ques/Q1_price_into_rupees.md @@ -0,0 +1,199 @@ +--- +title: Price into Rupees +tags: ['formatted-string', 'index', 'data-type'] +--- + +# Problem Statement + +Given a list of grocery items and their prices in paise (1 rupee = 100 paise), **return price in rupees** and remaining part in **paise** for the item *at the given index*. If the index is out of range, return **None**. + +**Example:** +```python +GroceryList = ['sugar', 'flour'] +PriceList = [4000, 7000] +get_price_in_rupees(GroceryList, PriceList, 1) # Flour:70 rupees 0 paise +get_price_in_rupees(['tablet', 'baking soda', 'milk', 'detergent'],[142, 841, 7621, 2221],1) # Baking Soda:8 rupees 41 paise +``` +First case: is in __00 form fully converts into rupees\ +Second case: baking soda is at index=1 and corresponds to `841` i.e. `8 rupees (800 paise) +41 paise`\ + + +# Solution + +```python test.py -r 'python test.py' + + +{% include '../function_type_and_modify_check_suffix.py.jinja' %} + +``` + +# Public Test Cases + +## Input 1 + +``` +GroceryList = ['apples', 'bread', 'carrots', 'detergent'] +PriceList = [1201, 2500, 7502, 4080] +is_equal( + get_price_in_rupees(GroceryList,PriceList,2), "Carrots:75 rupees 2 paise" + ) +``` + +## Output 1 + +``` +'Carrots:75 rupees 2 paise' +``` + +## Input 2 + +``` +GroceryList = ['mango', 'milk', 'eggs'] +PriceList = [1500, 5000, 999] +is_equal( + get_price_in_rupees(GroceryList, PriceList, 0), "Mango:15 rupees 0 paise" + ) +``` + +## Output 2 + +``` +'Mango:15 rupees 0 paise' +``` + +## Input 3 + +``` +GroceryList = ['onions', 'potatoes', 'tomatoes'] +PriceList = [450, 1050, 2300] +is_equal( + get_price_in_rupees(GroceryList, PriceList, 1), "Potatoes:10 rupees 50 paise" + ) +``` + +## Output 3 + +``` +'Potatoes:10 rupees 50 paise' +``` + +## Input 4 + +``` +GroceryList = ['mango', 'milk', 'eggs'] +PriceList = [1500, 5000, 999] +is_equal( + get_price_in_rupees(GroceryList, PriceList, 2), "Eggs:9 rupees 99 paise" + ) +``` + +## Output 4 + +``` +'Eggs:9 rupees 99 paise' +``` + +## Input 5 + +``` +GroceryList = ['onions', 'potatoes', 'tomatoes'] +PriceList = [450, 1050, 2300] +is_equal( + get_price_in_rupees(GroceryList, PriceList, -1), None + ) +``` + +## Output 5 + +``` +None +``` + +# Private Test Cases + +## Input 1 + +``` +GroceryList = ['onions', 'potatoes', 'tomatoes'] +PriceList = [450, 1050, 2300] +is_equal( + get_price_in_rupees(GroceryList, PriceList, 3), None + ) +``` + +## Output 1 + +``` +None +``` + +## Input 2 + +``` +is_equal( + get_price_in_rupees([], [], 0), + None +) +``` + +## Output 2 + +``` +None +``` + +## Input 3 + +``` +GroceryList = ['tea'] +PriceList = [905] +is_equal( + get_price_in_rupees(GroceryList, PriceList, 0), "Tea:9 rupees 5 paise" + ) +``` + +## Output 3 + +``` +'Tea:9 rupees 5 paise' +``` + +## Input 4 + +``` +GroceryList = ['chocolate-chip-cookies'] +PriceList = [2501] +is_equal( + get_price_in_rupees(GroceryList, PriceList, 0), "Chocolate-Chip-Cookies:25 rupees 1 paise" + ) +``` + +## Output 4 + +``` +'Chocolate-Chip-Cookies:25 rupees 1 paise' +``` + +## Input 5 + +``` +GroceryList = ['rice', 'wheat'] +PriceList = [1200, 3400] +is_equal( + get_price_in_rupees(GroceryList, PriceList, 5), None +) +``` + +## Output 5 + +``` +None +``` + From 823a85367d61a2908fa24087db5336a361cb1bf2 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Tue, 7 Jan 2025 21:42:57 +0530 Subject: [PATCH 04/43] Add files via upload 2. Data Processing - basic data processing patterns like mapping, filtering. input handled by driver code 3. Data Processing I/O - inputs from the stdin and print the output to stdout in the specified format (list of dictionaries). 4. Problem-solving - An input output based problem-solving which involves something different from basic data processing patterns. (good diffcultly) --- Programming Ques/Q2_find_repeated_elements.md | 112 ++++++++++++++ Programming Ques/Q3_process_licenseplate.md | 91 +++++++++++ Programming Ques/Q4_Kaprekar_constant.md | 144 ++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 Programming Ques/Q2_find_repeated_elements.md create mode 100644 Programming Ques/Q3_process_licenseplate.md create mode 100644 Programming Ques/Q4_Kaprekar_constant.md diff --git a/Programming Ques/Q2_find_repeated_elements.md b/Programming Ques/Q2_find_repeated_elements.md new file mode 100644 index 0000000..c076174 --- /dev/null +++ b/Programming Ques/Q2_find_repeated_elements.md @@ -0,0 +1,112 @@ +--- +title: Find Repeated Elements +tags: ['set', 'filtering'] +--- + +# Problem Statement + +Given a list, return a list of elements which are repeated in the input list. + +**Example** +```python +input list -> [1, 2, 3, 2, 3, 3, 4, 5, 6, 5] #here 2,3,5 have repetitions +output modified list -> [2, 3, 5] +``` + +# Solution + +```python test.py -r 'python test.py' + + +{% include '../function_type_and_modify_check_suffix.py.jinja' %} + +``` + +# Public Test Cases + +## Input 1 + +``` +is_equal( + find_repeated_elements([1, 2, 3, 2, 4, 5, 3, 6, 1]), [1, 2, 3] + ) +``` + +## Output 1 + +``` +[1, 2, 3] +``` + +## Input 2 + +``` +is_equal( + find_repeated_elements(['apple', 'banana', 'apple', 'cherry', 'banana']), ['apple', 'banana'] + ) +``` +## Output 2 + +``` +['apple', 'banana'] +``` + +## Input 3 + +``` +is_equal( + find_repeated_elements([10, 20, 30, 40]), [] + ) +``` + +## Output 3 + +``` +[] +``` + +# Private Test Cases + +## Input 1 + +``` +is_equal( + find_repeated_elements([7, 7, 7, 7, 7]), + [7] +) +is_equal( + find_repeated_elements([1, 2, 'apple', 2, 'banana', 'apple']), + [2, 'apple'] +) +is_equal( + find_repeated_elements([]), + [] +) +``` + +## Output 1 + +``` +[7] +[2, 'apple'] +[] +``` \ No newline at end of file diff --git a/Programming Ques/Q3_process_licenseplate.md b/Programming Ques/Q3_process_licenseplate.md new file mode 100644 index 0000000..0c326dd --- /dev/null +++ b/Programming Ques/Q3_process_licenseplate.md @@ -0,0 +1,91 @@ +--- +title: Process License Plate into state, RTO code, series, unique id +tags: ['dict', 'I/O', 'list slicing'] +--- + +# Problem Statement + +You need to process the license plate and return a list of dictionaries with keys as\ +1. `state`: (str) two letters which indicates the State or Union Territory in which the vehicle is registered.\ +2. `RTO code`: (int) a two-digit number allocated to a district RTO(s) within the respective state or Union Territory.\ +3. `series`: (str) 1 or 2 letter; show the ongoing registration series of respective RTO\ +4. `unique id` (int) between 1 and 9999; unique to each registration.\ + +Assume that inputs have: +- 1st line of input is the number of inputs (by the user) +- space between these 4 components `TN 12 L 2421` + +# Solution +```python test.py -r 'python test.py' + + +num = int(input()) +license_plates = [] +for _ in range(num): + license_plates.append(input().strip()) + + +``` + +# Public Test Cases + +## Input 1 + +``` +5 +MH 12 L 2039 +MH 12 LQ 2930 +KA 13 ZJ 4567 +TN 08 B 7890 +DL 09 X 1023 +``` + +## Output 1 + +``` +[{'state': 'MH', 'RTO code': 12, 'series': 'L', 'unique id': 2039}, {'state': 'MH', 'RTO code': 12, 'series': 'LQ', 'unique id': 2930}, {'state': 'KA', 'RTO code': 13, 'series': 'ZJ', 'unique id': 4567}, {'state': 'TN', 'RTO code': 8, 'series': 'B', 'unique id': 7890}, {'state': 'DL', 'RTO code': 9, 'series': 'X', 'unique id': 1023}] +``` + +## Input 2 + +``` +3 +KA 10 AB 1234 +MH 05 XY 5678 +TN 03 PQ 9999 +``` + +## Output 2 + +``` +[{'state': 'KA', 'RTO code': 10, 'series': 'AB', 'unique id': 1234}, {'state': 'MH', 'RTO code': 5, 'series': 'XY', 'unique id': 5678}, {'state': 'TN', 'RTO code': 3, 'series': 'PQ', 'unique id': 9999}] +``` + + +# Private Test Cases + +## Input 1 + +``` +0 +``` + +## Output 1 + +``` +[] +``` diff --git a/Programming Ques/Q4_Kaprekar_constant.md b/Programming Ques/Q4_Kaprekar_constant.md new file mode 100644 index 0000000..b1108d5 --- /dev/null +++ b/Programming Ques/Q4_Kaprekar_constant.md @@ -0,0 +1,144 @@ +--- +title: Kaprekar's constant +tags: ['I/O', 'while loop', 'sort', 'join'] +--- + +# Problem Statement + +1. Take any **four-digit number**, using at least two different digits (*check for same for a given input*). +2. Arrange the digits in **descending** and then in **ascending order** to get two four-digit numbers. +3. **Subtract** the smaller number from the bigger number. +4. Go back to **step 2** and repeat until you reach 6174 (Kaprekar's constant). +5. Return the **number of steps (int) it took until the difference is 6174.** + +**Example:** +``` +1459 #3 +``` +largest - smallest = +9541 – 1459 = 8082\ +8820 – 0288 = 8532\ +8532 – 2358 = 6174\ +Hence, it took 4 steps to reach 6174. (If the input was 6174, then 0 steps)\ + +# Solution + +```python test.py -r 'python test.py' + +``` + +# Public Test Cases + +## Input 1 + +``` +1631 +``` + +## Output 1 + +``` +7 +``` + +## Input 2 + +``` +2468 +``` + +## Output 2 + +``` +1 +``` + +## Input 3 + +``` +3839 +``` + +## Output 3 + +``` +5 +``` + +# Private Test Cases + +## Input 1 + +``` +6174 +``` + +## Output 1 + +``` +0 +``` + +## Input 2 + +``` +24Ab +``` + +## Output 2 + +``` +None +``` + +## Input 3 + +``` +1111 +``` + +## Output 3 + +``` +None +``` + +## Input 4 + +``` +21 +``` + +## Output 4 + +``` +None +``` From 2515fbea494f777596552deab0d7eeb727f06e87 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Tue, 7 Jan 2025 22:24:03 +0530 Subject: [PATCH 05/43] Update README.md fixed terminal output image --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2eda1fc..91026fc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # python-programming-questions -The 4 Programming Questions evaluate correctly in my local system:\ -![image](https://github.com/user-attachments/assets/74b68136-80fd-4f3a-b984-bb9c4d5be0ac) +The 4 Programming Questions evaluate correctly in the local-system:\ +![400818277-74b68136-80fd-4f3a-b984-bb9c4d5be0ac](https://github.com/user-attachments/assets/47b9f3ef-7781-4471-b85d-dca805903db7) The type of each question is given below: 1. **Data types** - basic operations on datatypes *(str -> f-string, title(), list->indexing, int-> //, %)* and not used loops. input outputs are handled by a driver code. From ca59d7ba551d670ce5bfc481f28b28932b2dd628 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Tue, 7 Jan 2025 22:58:09 +0530 Subject: [PATCH 06/43] Update Q2_find_repeated_elements.md added more private test cases changed problem statement --- Programming Ques/Q2_find_repeated_elements.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Programming Ques/Q2_find_repeated_elements.md b/Programming Ques/Q2_find_repeated_elements.md index c076174..435c439 100644 --- a/Programming Ques/Q2_find_repeated_elements.md +++ b/Programming Ques/Q2_find_repeated_elements.md @@ -5,12 +5,12 @@ tags: ['set', 'filtering'] # Problem Statement -Given a list, return a list of elements which are repeated in the input list. +Given a list, return a list containing elements which are repeated, equal. -**Example** +**Example:** ```python -input list -> [1, 2, 3, 2, 3, 3, 4, 5, 6, 5] #here 2,3,5 have repetitions -output modified list -> [2, 3, 5] +input list -> [1, 2, 3, 2, 3, 3, 4,"A","b","B","A"] #here 2,3,'A' have repetitions +output list -> [2, 3, 'A'] ``` # Solution @@ -94,7 +94,7 @@ is_equal( [7] ) is_equal( - find_repeated_elements([1, 2, 'apple', 2, 'banana', 'apple']), + find_repeated_elements([1, 2, 'apple', 2, 'banana', 'apple','bAnana']), [2, 'apple'] ) is_equal( @@ -109,4 +109,4 @@ is_equal( [7] [2, 'apple'] [] -``` \ No newline at end of file +``` From dcb273a72778fb506814793272b8543037bcf209 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Tue, 7 Jan 2025 23:34:53 +0530 Subject: [PATCH 07/43] Update Q3_process_licenseplate.md refined problem statement --- Programming Ques/Q3_process_licenseplate.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Programming Ques/Q3_process_licenseplate.md b/Programming Ques/Q3_process_licenseplate.md index 0c326dd..271ee71 100644 --- a/Programming Ques/Q3_process_licenseplate.md +++ b/Programming Ques/Q3_process_licenseplate.md @@ -5,15 +5,15 @@ tags: ['dict', 'I/O', 'list slicing'] # Problem Statement -You need to process the license plate and return a list of dictionaries with keys as\ -1. `state`: (str) two letters which indicates the State or Union Territory in which the vehicle is registered.\ -2. `RTO code`: (int) a two-digit number allocated to a district RTO(s) within the respective state or Union Territory.\ -3. `series`: (str) 1 or 2 letter; show the ongoing registration series of respective RTO\ -4. `unique id` (int) between 1 and 9999; unique to each registration.\ - -Assume that inputs have: -- 1st line of input is the number of inputs (by the user) -- space between these 4 components `TN 12 L 2421` +User inputs license-plates. Process these license-plates and return a list of dictionaries with keys as: +1. `state`: (str) two letters which indicates the State or Union Territory in which the vehicle is registered. +2. `RTO code`: (int) a two-digit number allocated to a district RTO(s) within the respective state or Union Territory. +3. `series`: (str) 1 or 2 letter; show the ongoing registration series of respective RTO +4. `unique id` (int) between 1 and 9999; unique to each registration. + +Input preconditions: +- 1st line of input is total number of license-plates +- 2nd line onwards input license-plate in the format `TN 12 L 2421`. Press enter if multiple license-plates. # Solution ```python test.py -r 'python test.py' From e888d64fff835ccaa5104e8439839c838f83531a Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 00:08:46 +0530 Subject: [PATCH 08/43] Update Q4_Kaprekar_constant.md refined problem statement --- Programming Ques/Q4_Kaprekar_constant.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Programming Ques/Q4_Kaprekar_constant.md b/Programming Ques/Q4_Kaprekar_constant.md index b1108d5..405ffcc 100644 --- a/Programming Ques/Q4_Kaprekar_constant.md +++ b/Programming Ques/Q4_Kaprekar_constant.md @@ -1,25 +1,27 @@ --- -title: Kaprekar's constant +title: Kaprekar's constant (6174) tags: ['I/O', 'while loop', 'sort', 'join'] --- # Problem Statement - -1. Take any **four-digit number**, using at least two different digits (*check for same for a given input*). -2. Arrange the digits in **descending** and then in **ascending order** to get two four-digit numbers. -3. **Subtract** the smaller number from the bigger number. -4. Go back to **step 2** and repeat until you reach 6174 (Kaprekar's constant). -5. Return the **number of steps (int) it took until the difference is 6174.** +Find out: how many steps are required to arrive at 6174 (Kaprekar's constant). +Follow the Method below: +1. Input any **four-digit number**. Check for *4-digits input and at-least 2-digits are unique* +2. Find the **smallest & largest possible 4-digit number** which can be made from the given number. +3. **Subtract** the smallest from the largest number. Note the difference number. +4. Go-back to **step 2** and repeat until the difference becomes 6174. +5. Calculate the **number of steps (int) required to reach 6174.** **Example:** ``` -1459 #3 +1459 +#output: 3 ``` -largest - smallest = +largest - smallest =\ 9541 – 1459 = 8082\ 8820 – 0288 = 8532\ 8532 – 2358 = 6174\ -Hence, it took 4 steps to reach 6174. (If the input was 6174, then 0 steps)\ +So, it took 3-steps to reach 6174. (If the input was 6174, then 0-steps required.) # Solution @@ -42,7 +44,7 @@ def Kaprekar(): steps=0 if len(Num) != 4 or not Num.isdigit() or len(set(Num)) < 2: - return None # Return None if invalid input (non-4 digits or all digits the same) + return None # Return None if invalid input (not all 4 digits are the same) if int(Num) == 6174: return 0 From 196b6fb703b0bdcbe25cead34f663dabd21ad073 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 11:13:38 +0530 Subject: [PATCH 09/43] Update and rename Q1_price_into_rupees.md to Q1_price_into_dollars.md changed into rupee into dollar question (as paise isn't use to store data much but dollar for export) and removed unnecessary grocery items list rather modify in place. --- Programming Ques/Q1_price_into_dollars.md | 194 +++++++++++++++++++++ Programming Ques/Q1_price_into_rupees.md | 199 ---------------------- 2 files changed, 194 insertions(+), 199 deletions(-) create mode 100644 Programming Ques/Q1_price_into_dollars.md delete mode 100644 Programming Ques/Q1_price_into_rupees.md diff --git a/Programming Ques/Q1_price_into_dollars.md b/Programming Ques/Q1_price_into_dollars.md new file mode 100644 index 0000000..8babce6 --- /dev/null +++ b/Programming Ques/Q1_price_into_dollars.md @@ -0,0 +1,194 @@ +--- +title: Price into Dollars +tags: ['formatted-string', 'index', 'data-type'] +--- + +# Problem Statement + +Given a list of prices of items in ruppes (1 dollar = 85 rupees), **modify in place the price to dollars and cents(1 dollar = 100 cents)** for the item *at the given index* (don't modify other indices). If the index is out of range, return **None**. +Assume the `price_list` is list of valid **integers**.\ +String output has no decimal points (as the remaining rupees is written as cents) + +**Example:** +```python +PriceList = [4000, 7000] +get_price_in_dollars(PriceList, 1) # list modified [4000, '82 dollars 35 cents'] +get_price_in_dollars([142, 841, 7621, 2221],1) #list modified [142, '9 dollars 89 cents',7621,1) +``` +First case: 7000 rupeess -> 82 dollars 35 cents\ +Second case: at index=1 is `841` i.e. `9 dollars 89 cents` (85 rupees -> 1 dollar & 1 dollar -> 100 cents) + + +# Solution + +```python test.py -r 'python test.py' + + +{% include '../function_type_and_modify_check_suffix.py.jinja' %} + +``` + +# Public Test Cases + +## Input 1 + +```python +PriceList = [1201, 2500, 7502, 4080] +modify_check( + lambda x: get_price_in_dollars(x, 0), PriceList, ['14 dollars 12 cents', 2500, 7502, 4080], should_modify=True +) +``` + +## Output 1 + +``` +['14 dollars 12 cents', 2500, 7502, 4080] +``` + +## Input 2 + +```python +PriceList = [1500, 5000, 999] +modify_check( + lambda x: get_price_in_dollars(x, 0), PriceList, ['17 dollars 64 cents', 5000, 999], should_modify=True +) +``` + +## Output 2 + +``` +['17 dollars 64 cents', 5000, 999] +``` + +## Input 3 + +```python +PriceList = [450, 1050, 2300] +modify_check( + lambda x: get_price_in_dollars(x, 1), PriceList, [450, '12 dollars 35 cents', 2300], should_modify=True +) +``` + +## Output 3 + +``` +[450, '12 dollars 35 cents', 2300] +``` + +## Input 4 + +```python +PriceList = [1500, 5000, 999] +modify_check( + lambda x: get_price_in_dollars(x, 2), PriceList, [1500, 5000, '11 dollars 75 cents'], should_modify=True +) +``` + +## Output 4 + +``` +[1500, 5000, '11 dollars 75 cents'] +``` + +## Input 5 + +```python +PriceList = [450, 1050, 2300] +modify_check( + lambda x: get_price_in_dollars(x, -1), PriceList, None, should_modify=False + ) +``` + +## Output 5 + +``` +None +``` + + +# Private Test Cases + +## Input 1 (out of range index) + +```python +PriceList = [450, 1050, 2300] +modify_check( + lambda x: get_price_in_dollars(x, 3), PriceList, None, should_modify=False +) +``` + +## Output 1 + +``` +None +``` + +## Input 2 (empty list) + +```python +modify_check( + lambda x: get_price_in_dollars(x, 0), + [], + None, + should_modify=False +) +``` + +## Output 2 + +``` +None +``` + +## Input 3 (1 item list) + +```python +PriceList = [905] +modify_check( + lambda x: get_price_in_dollars(x, 0), PriceList, ['10 dollars 64 cents'], should_modify=True +) +``` + +## Output 3 + +``` +['10 dollars 64 cents'] +``` + +## Input 4 (1 item list) + +```python +PriceList = [2501] +modify_check( + lambda x: get_price_in_dollars(x, 0), PriceList, ['29 dollars 42 cents'], should_modify=True +) +``` + +## Output 4 + +``` +['29 dollars 42 cents'] +``` + +## Input 5 (out of range index) + +```python +PriceList = [1200, 3400] +modify_check( + lambda x: get_price_in_dollars(x, 5), PriceList, None, should_modify=False +) +``` + +## Output 5 + +``` +None +``` + diff --git a/Programming Ques/Q1_price_into_rupees.md b/Programming Ques/Q1_price_into_rupees.md deleted file mode 100644 index b1833b8..0000000 --- a/Programming Ques/Q1_price_into_rupees.md +++ /dev/null @@ -1,199 +0,0 @@ ---- -title: Price into Rupees -tags: ['formatted-string', 'index', 'data-type'] ---- - -# Problem Statement - -Given a list of grocery items and their prices in paise (1 rupee = 100 paise), **return price in rupees** and remaining part in **paise** for the item *at the given index*. If the index is out of range, return **None**. - -**Example:** -```python -GroceryList = ['sugar', 'flour'] -PriceList = [4000, 7000] -get_price_in_rupees(GroceryList, PriceList, 1) # Flour:70 rupees 0 paise -get_price_in_rupees(['tablet', 'baking soda', 'milk', 'detergent'],[142, 841, 7621, 2221],1) # Baking Soda:8 rupees 41 paise -``` -First case: is in __00 form fully converts into rupees\ -Second case: baking soda is at index=1 and corresponds to `841` i.e. `8 rupees (800 paise) +41 paise`\ - - -# Solution - -```python test.py -r 'python test.py' - - -{% include '../function_type_and_modify_check_suffix.py.jinja' %} - -``` - -# Public Test Cases - -## Input 1 - -``` -GroceryList = ['apples', 'bread', 'carrots', 'detergent'] -PriceList = [1201, 2500, 7502, 4080] -is_equal( - get_price_in_rupees(GroceryList,PriceList,2), "Carrots:75 rupees 2 paise" - ) -``` - -## Output 1 - -``` -'Carrots:75 rupees 2 paise' -``` - -## Input 2 - -``` -GroceryList = ['mango', 'milk', 'eggs'] -PriceList = [1500, 5000, 999] -is_equal( - get_price_in_rupees(GroceryList, PriceList, 0), "Mango:15 rupees 0 paise" - ) -``` - -## Output 2 - -``` -'Mango:15 rupees 0 paise' -``` - -## Input 3 - -``` -GroceryList = ['onions', 'potatoes', 'tomatoes'] -PriceList = [450, 1050, 2300] -is_equal( - get_price_in_rupees(GroceryList, PriceList, 1), "Potatoes:10 rupees 50 paise" - ) -``` - -## Output 3 - -``` -'Potatoes:10 rupees 50 paise' -``` - -## Input 4 - -``` -GroceryList = ['mango', 'milk', 'eggs'] -PriceList = [1500, 5000, 999] -is_equal( - get_price_in_rupees(GroceryList, PriceList, 2), "Eggs:9 rupees 99 paise" - ) -``` - -## Output 4 - -``` -'Eggs:9 rupees 99 paise' -``` - -## Input 5 - -``` -GroceryList = ['onions', 'potatoes', 'tomatoes'] -PriceList = [450, 1050, 2300] -is_equal( - get_price_in_rupees(GroceryList, PriceList, -1), None - ) -``` - -## Output 5 - -``` -None -``` - -# Private Test Cases - -## Input 1 - -``` -GroceryList = ['onions', 'potatoes', 'tomatoes'] -PriceList = [450, 1050, 2300] -is_equal( - get_price_in_rupees(GroceryList, PriceList, 3), None - ) -``` - -## Output 1 - -``` -None -``` - -## Input 2 - -``` -is_equal( - get_price_in_rupees([], [], 0), - None -) -``` - -## Output 2 - -``` -None -``` - -## Input 3 - -``` -GroceryList = ['tea'] -PriceList = [905] -is_equal( - get_price_in_rupees(GroceryList, PriceList, 0), "Tea:9 rupees 5 paise" - ) -``` - -## Output 3 - -``` -'Tea:9 rupees 5 paise' -``` - -## Input 4 - -``` -GroceryList = ['chocolate-chip-cookies'] -PriceList = [2501] -is_equal( - get_price_in_rupees(GroceryList, PriceList, 0), "Chocolate-Chip-Cookies:25 rupees 1 paise" - ) -``` - -## Output 4 - -``` -'Chocolate-Chip-Cookies:25 rupees 1 paise' -``` - -## Input 5 - -``` -GroceryList = ['rice', 'wheat'] -PriceList = [1200, 3400] -is_equal( - get_price_in_rupees(GroceryList, PriceList, 5), None -) -``` - -## Output 5 - -``` -None -``` - From aefc89a88c47791d9b28a717a8f3e9c9e00fc2ed Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 11:26:39 +0530 Subject: [PATCH 10/43] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 91026fc..c482dbc 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # python-programming-questions The 4 Programming Questions evaluate correctly in the local-system:\ -![400818277-74b68136-80fd-4f3a-b984-bb9c4d5be0ac](https://github.com/user-attachments/assets/47b9f3ef-7781-4471-b85d-dca805903db7) +![image](https://github.com/user-attachments/assets/b5ee3a72-0588-4bc9-b634-f6e84d1233be) The type of each question is given below: -1. **Data types** - basic operations on datatypes *(str -> f-string, title(), list->indexing, int-> //, %)* and not used loops. input outputs are handled by a driver code. +1. **Data types** - basic operations on datatypes *(str -> f-string, list->indexing, int-> //, %,*)* and not used loops. input are handled by a driver code, check of modified list. 2. **Data Processing** - basic data processing patterns like *mapping, filtering*. input handled by driver code 3. **Data Processing I/O** - inputs from the stdin and print the output to stdout in the specified format (list of dictionaries). -4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly) +4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly maybe OPPE 2 level) From 4526cca7032e00924f4df1b160fc93cbe590235b Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 11:27:56 +0530 Subject: [PATCH 11/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c482dbc..4dc7880 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ The 4 Programming Questions evaluate correctly in the local-system:\ ![image](https://github.com/user-attachments/assets/b5ee3a72-0588-4bc9-b634-f6e84d1233be) The type of each question is given below: -1. **Data types** - basic operations on datatypes *(str -> f-string, list->indexing, int-> //, %,*)* and not used loops. input are handled by a driver code, check of modified list. +1. **Data types** - basic operations on datatypes (str -> f-string, list->indexing, int-> //, %,*) and not used loops. input are handled by a driver code, check the modified list. 2. **Data Processing** - basic data processing patterns like *mapping, filtering*. input handled by driver code 3. **Data Processing I/O** - inputs from the stdin and print the output to stdout in the specified format (list of dictionaries). 4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly maybe OPPE 2 level) From 97a7320a25a7185e2d0b11771fdb413aecd310be Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 11:30:00 +0530 Subject: [PATCH 12/43] Update Q2_find_repeated_elements.md --- Programming Ques/Q2_find_repeated_elements.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Programming Ques/Q2_find_repeated_elements.md b/Programming Ques/Q2_find_repeated_elements.md index 435c439..57a1964 100644 --- a/Programming Ques/Q2_find_repeated_elements.md +++ b/Programming Ques/Q2_find_repeated_elements.md @@ -5,11 +5,11 @@ tags: ['set', 'filtering'] # Problem Statement -Given a list, return a list containing elements which are repeated, equal. +Given a list, return a list containing elements which are repeated, equal. (case, type sensistive) **Example:** ```python -input list -> [1, 2, 3, 2, 3, 3, 4,"A","b","B","A"] #here 2,3,'A' have repetitions +input list -> [1, 2, 3, 2, 3, 3, 4,'A','b','B','A'] #here 2,3,'A' have repetitions output list -> [2, 3, 'A'] ``` From af0d15a103c64c0e48bcfd451f0af9b2670390b4 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 11:30:32 +0530 Subject: [PATCH 13/43] Update Q3_process_licenseplate.md --- Programming Ques/Q3_process_licenseplate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Programming Ques/Q3_process_licenseplate.md b/Programming Ques/Q3_process_licenseplate.md index 271ee71..3d2c7d9 100644 --- a/Programming Ques/Q3_process_licenseplate.md +++ b/Programming Ques/Q3_process_licenseplate.md @@ -5,7 +5,7 @@ tags: ['dict', 'I/O', 'list slicing'] # Problem Statement -User inputs license-plates. Process these license-plates and return a list of dictionaries with keys as: +User inputs license-plates. Process these license-plates and **print a list of dictionaries*** with keys as: 1. `state`: (str) two letters which indicates the State or Union Territory in which the vehicle is registered. 2. `RTO code`: (int) a two-digit number allocated to a district RTO(s) within the respective state or Union Territory. 3. `series`: (str) 1 or 2 letter; show the ongoing registration series of respective RTO From 7271f77e05058020a5ea2c0926db9a6f33d931f2 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 11:41:22 +0530 Subject: [PATCH 14/43] Add files via upload --- ...tion_type_and_modify_check_suffix.py.jinja | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 function_type_and_modify_check_suffix.py.jinja diff --git a/function_type_and_modify_check_suffix.py.jinja b/function_type_and_modify_check_suffix.py.jinja new file mode 100644 index 0000000..056fa5e --- /dev/null +++ b/function_type_and_modify_check_suffix.py.jinja @@ -0,0 +1,75 @@ +from copy import deepcopy + +{% raw %} +def order_repr(d): + '''Print in lexicographical order of repr if dict and set''' + if isinstance(d,dict): + d = sorted(d.items(), key=lambda x:order_repr(x[0]) ) + return f"{{{', '.join(f'{order_repr(k)}: {order_repr(v)}' for k,v in d)}}}" + elif isinstance(d,set): + return f"{{{', '.join(map(order_repr,sorted(d, key=order_repr)))}}}" + else: + return repr(d) +{% endraw %} + +def order_print(d): + print(order_repr(d)) + + +import traceback +def except_wrap(func): + def inner_func(*args,**kwargs): + try: + func(*args,**kwargs) + except AssertionError as e: + print(e) + except Exception as e: + traceback.print_exception(e,limit=-1, file=sys.stdout) + return inner_func + + +def assert_equal(actual_out, expected_out, show=True): + assert expected_out is None or actual_out is not None,\ + "No output returned.\nAre you returning the output? It seems like you are not returning anything." + assert actual_out == expected_out and type(actual_out) == type(expected_out),\ + ( + 'Your output does not match expected output.\n' + f'Expected ouput (type: {type(expected_out).__name__}):\n{order_repr(expected_out)}\n' + f'Your output (type: {type(actual_out).__name__}):\n{order_repr(actual_out)}' + ) + if show: + order_print(actual_out) + +is_equal = except_wrap(assert_equal) + +@except_wrap +def modify_check(func, in_obj, expected, should_modify=True): + in_obj_old = deepcopy(in_obj) + actual_out = func(in_obj) + if should_modify: + assert in_obj_old == expected or in_obj != in_obj_old,\ + ( + f'Input {type(in_obj).__name__} is not modified. You should modify the input {type(in_obj).__name__}.\n' + f'Original ({type(in_obj).__name__}):\n{order_repr(in_obj)}\n' + f'Expected modification:\n{order_repr(expected)}' + ) + assert in_obj == expected,\ + ( + f'Incorrect modifcation of the input {type(in_obj).__name__}.\n' + f'Expected modification:\n{order_repr(expected)}\n' + f'Your modification:\n{order_repr(in_obj)}' + ) + order_print(in_obj) + else: + assert_equal(actual_out, expected,show=False) + assert in_obj_old == in_obj,\ + ( + f'Input {type(in_obj).__name__} is modified. You shouldn\'t modify the input {type(in_obj).__name__}.\n' + f'Original input ({type(in_obj).__name__}):\n{order_repr(in_obj_old)}\n' + f'Your modification:\n{order_repr(in_obj)}' + ) + order_print(actual_out) + +import sys +exec(sys.stdin.read()) + From 12b5fec3a2d9024347f7e66c380263e33abad488 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:13:10 +0530 Subject: [PATCH 15/43] Update and rename function_type_and_modify_check_suffix.py.jinja to is_equal_forloop_modify_check_suffix.py.jinja --- ...equal_forloop_modify_check_suffix.py.jinja | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) rename function_type_and_modify_check_suffix.py.jinja => is_equal_forloop_modify_check_suffix.py.jinja (67%) diff --git a/function_type_and_modify_check_suffix.py.jinja b/is_equal_forloop_modify_check_suffix.py.jinja similarity index 67% rename from function_type_and_modify_check_suffix.py.jinja rename to is_equal_forloop_modify_check_suffix.py.jinja index 056fa5e..0c04485 100644 --- a/function_type_and_modify_check_suffix.py.jinja +++ b/is_equal_forloop_modify_check_suffix.py.jinja @@ -70,6 +70,40 @@ def modify_check(func, in_obj, expected, should_modify=True): ) order_print(actual_out) +import ast +import inspect + +def check_for_loops(func): + """Check if the given function contains any 'for' loops, ignoring the docstring.""" + try: + # Get the source code of the function as a string + source_code = inspect.getsource(func) + + # Remove the docstring part if it exists + lines = source_code.splitlines() + if lines[0].strip().startswith('"""') or lines[0].strip().startswith("'''"): + # If the function has a docstring, remove it from the source code + docstring_end_index = lines.index('"""') + 1 if lines[0].strip().startswith('"""') else lines.index("'''") + 1 + lines = lines[docstring_end_index:] + + # Join the lines back to form the cleaned source code (with the docstring removed) + cleaned_source_code = "\n".join(lines) + + # Parse the cleaned source code into an AST + tree = ast.parse(cleaned_source_code) + + # Traverse the AST and look for for-loops + for node in ast.walk(tree): + if isinstance(node, ast.For): + print(f"Found a 'for' loop in the function {func.__name__}.") + return True + + return False + except Exception as e: + print(f"Error while checking 'for' loops: {e}") + return False + + import sys exec(sys.stdin.read()) From b27d620366eea94972c5b4b4dd63c6ec52c231e2 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:25:21 +0530 Subject: [PATCH 16/43] Update Q1_price_into_dollars.md for loop checking --- Programming Ques/Q1_price_into_dollars.md | 78 +++++++++++++---------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/Programming Ques/Q1_price_into_dollars.md b/Programming Ques/Q1_price_into_dollars.md index 8babce6..af45920 100644 --- a/Programming Ques/Q1_price_into_dollars.md +++ b/Programming Ques/Q1_price_into_dollars.md @@ -8,7 +8,7 @@ tags: ['formatted-string', 'index', 'data-type'] Given a list of prices of items in ruppes (1 dollar = 85 rupees), **modify in place the price to dollars and cents(1 dollar = 100 cents)** for the item *at the given index* (don't modify other indices). If the index is out of range, return **None**. Assume the `price_list` is list of valid **integers**.\ String output has no decimal points (as the remaining rupees is written as cents) - +**Don't use any loops** **Example:** ```python PriceList = [4000, 7000] @@ -31,7 +31,7 @@ def get_price_in_dollars(price_list: list, index: int) -> str: -{% include '../function_type_and_modify_check_suffix.py.jinja' %} +{% include '../is_equal_forloop_modify_check_suffix.py.jinja' %} ``` @@ -41,9 +41,10 @@ def get_price_in_dollars(price_list: list, index: int) -> str: ```python PriceList = [1201, 2500, 7502, 4080] -modify_check( - lambda x: get_price_in_dollars(x, 0), PriceList, ['14 dollars 12 cents', 2500, 7502, 4080], should_modify=True -) +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, 0), PriceList, ['14 dollars 12 cents', 2500, 7502, 4080], should_modify=True + ) ``` ## Output 1 @@ -56,9 +57,10 @@ modify_check( ```python PriceList = [1500, 5000, 999] -modify_check( - lambda x: get_price_in_dollars(x, 0), PriceList, ['17 dollars 64 cents', 5000, 999], should_modify=True -) +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, 0), PriceList, ['17 dollars 64 cents', 5000, 999], should_modify=True + ) ``` ## Output 2 @@ -71,9 +73,10 @@ modify_check( ```python PriceList = [450, 1050, 2300] -modify_check( - lambda x: get_price_in_dollars(x, 1), PriceList, [450, '12 dollars 35 cents', 2300], should_modify=True -) +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, 1), PriceList, [450, '12 dollars 35 cents', 2300], should_modify=True + ) ``` ## Output 3 @@ -86,9 +89,10 @@ modify_check( ```python PriceList = [1500, 5000, 999] -modify_check( - lambda x: get_price_in_dollars(x, 2), PriceList, [1500, 5000, '11 dollars 75 cents'], should_modify=True -) +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, 2), PriceList, [1500, 5000, '11 dollars 75 cents'], should_modify=True + ) ``` ## Output 4 @@ -101,8 +105,9 @@ modify_check( ```python PriceList = [450, 1050, 2300] -modify_check( - lambda x: get_price_in_dollars(x, -1), PriceList, None, should_modify=False +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, -1), PriceList, None, should_modify=False ) ``` @@ -119,9 +124,10 @@ None ```python PriceList = [450, 1050, 2300] -modify_check( - lambda x: get_price_in_dollars(x, 3), PriceList, None, should_modify=False -) +if not check_for_loops(get_price_in_dollars): #if for loop found prints "Found a 'for' loop in the function {func.__name__}.") + modify_check( + lambda x: get_price_in_dollars(x, 3), PriceList, None, should_modify=False + ) ``` ## Output 1 @@ -133,12 +139,13 @@ None ## Input 2 (empty list) ```python -modify_check( - lambda x: get_price_in_dollars(x, 0), - [], - None, - should_modify=False -) +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, 0), + [], + None, + should_modify=False + ) ``` ## Output 2 @@ -151,9 +158,10 @@ None ```python PriceList = [905] -modify_check( - lambda x: get_price_in_dollars(x, 0), PriceList, ['10 dollars 64 cents'], should_modify=True -) +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, 0), PriceList, ['10 dollars 64 cents'], should_modify=True + ) ``` ## Output 3 @@ -166,9 +174,10 @@ modify_check( ```python PriceList = [2501] -modify_check( - lambda x: get_price_in_dollars(x, 0), PriceList, ['29 dollars 42 cents'], should_modify=True -) +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, 0), PriceList, ['29 dollars 42 cents'], should_modify=True + ) ``` ## Output 4 @@ -181,9 +190,10 @@ modify_check( ```python PriceList = [1200, 3400] -modify_check( - lambda x: get_price_in_dollars(x, 5), PriceList, None, should_modify=False -) +if not check_for_loops(get_price_in_dollars): + modify_check( + lambda x: get_price_in_dollars(x, 5), PriceList, None, should_modify=False + ) ``` ## Output 5 From 20bb1e2f877fcd2e0fd3aa7bc3d2cd5a544d9c05 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:41:58 +0530 Subject: [PATCH 17/43] Update is_equal_loops_modify_check_suffix.py.jinja --- is_equal_forloop_modify_check_suffix.py.jinja | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/is_equal_forloop_modify_check_suffix.py.jinja b/is_equal_forloop_modify_check_suffix.py.jinja index 0c04485..9b66170 100644 --- a/is_equal_forloop_modify_check_suffix.py.jinja +++ b/is_equal_forloop_modify_check_suffix.py.jinja @@ -70,37 +70,46 @@ def modify_check(func, in_obj, expected, should_modify=True): ) order_print(actual_out) -import ast import inspect +import ast def check_for_loops(func): - """Check if the given function contains any 'for' loops, ignoring the docstring.""" + """Check if the given function contains any 'for' or 'while' loops, ignoring the docstring.""" try: - # Get the source code of the function as a string + # Get the source code of the function source_code = inspect.getsource(func) # Remove the docstring part if it exists - lines = source_code.splitlines() - if lines[0].strip().startswith('"""') or lines[0].strip().startswith("'''"): - # If the function has a docstring, remove it from the source code - docstring_end_index = lines.index('"""') + 1 if lines[0].strip().startswith('"""') else lines.index("'''") + 1 - lines = lines[docstring_end_index:] - - # Join the lines back to form the cleaned source code (with the docstring removed) - cleaned_source_code = "\n".join(lines) - + if '"""' in source_code or "'''" in source_code: + # Handling the docstring removal + start_idx = source_code.find('"""') + end_idx = source_code.find('"""', start_idx + 3) + if start_idx != -1 and end_idx != -1: + source_code = source_code[:start_idx] + source_code[end_idx + 3:] + else: + start_idx = source_code.find("'''") + end_idx = source_code.find("'''", start_idx + 3) + if start_idx != -1 and end_idx != -1: + source_code = source_code[:start_idx] + source_code[end_idx + 3:] + + # Normalize indentation to spaces (4 spaces) + source_code = source_code.replace("\t", " ") + + # Strip any leading/trailing whitespace that might affect parsing + source_code = source_code.strip() + # Parse the cleaned source code into an AST - tree = ast.parse(cleaned_source_code) + tree = ast.parse(source_code) - # Traverse the AST and look for for-loops + # Check for any 'for' or 'while' loops for node in ast.walk(tree): - if isinstance(node, ast.For): - print(f"Found a 'for' loop in the function {func.__name__}.") + if isinstance(node, (ast.For, ast.While)): + print(f"Found a loop (for/while) in the function {func.__name__}.") return True return False except Exception as e: - print(f"Error while checking 'for' loops: {e}") + print(f"Error while checking loops: {e}") return False From edf2724497e796434e0810b9f80ba9fd7208cb9a Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:43:33 +0530 Subject: [PATCH 18/43] Rename is_equal_forloop_modify_check_suffix.py.jinja to is_equal_loops_modify_check_suffix.py.jinja --- ...suffix.py.jinja => is_equal_loops_modify_check_suffix.py.jinja | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename is_equal_forloop_modify_check_suffix.py.jinja => is_equal_loops_modify_check_suffix.py.jinja (100%) diff --git a/is_equal_forloop_modify_check_suffix.py.jinja b/is_equal_loops_modify_check_suffix.py.jinja similarity index 100% rename from is_equal_forloop_modify_check_suffix.py.jinja rename to is_equal_loops_modify_check_suffix.py.jinja From 3c7504d6a74397ace4a850ecc8940b77a276ef71 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:45:08 +0530 Subject: [PATCH 19/43] Update Q1_price_into_dollars.md --- Programming Ques/Q1_price_into_dollars.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Programming Ques/Q1_price_into_dollars.md b/Programming Ques/Q1_price_into_dollars.md index af45920..49898eb 100644 --- a/Programming Ques/Q1_price_into_dollars.md +++ b/Programming Ques/Q1_price_into_dollars.md @@ -7,8 +7,8 @@ tags: ['formatted-string', 'index', 'data-type'] Given a list of prices of items in ruppes (1 dollar = 85 rupees), **modify in place the price to dollars and cents(1 dollar = 100 cents)** for the item *at the given index* (don't modify other indices). If the index is out of range, return **None**. Assume the `price_list` is list of valid **integers**.\ -String output has no decimal points (as the remaining rupees is written as cents) -**Don't use any loops** +String output has no decimal points (as the remaining rupees is written as cents)\ +**Don't use any loops**\ **Example:** ```python PriceList = [4000, 7000] @@ -26,12 +26,13 @@ Second case: at index=1 is `841` i.e. `9 dollars 89 cents` (85 rupees -> 1 dolla def get_price_in_dollars(price_list: list, index: int) -> str: if 0 <= index < len(price_list): - price_list[index] = f"{price_list[index]//85} dollars {price_list[index]%85 *100//85} cents" + rs = int(price_list[index]) + price_list[index] = f"{rs // 85} dollars {(rs%85) *100 // 85} cents" return None -{% include '../is_equal_forloop_modify_check_suffix.py.jinja' %} +{% include '../is_equal_loops_modify_check_suffix.py.jinja' %} ``` From d8e129440fa09c53cbe7f4f1555e1cf6ff4d1d34 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:46:46 +0530 Subject: [PATCH 20/43] Update Q2_find_repeated_elements.md --- Programming Ques/Q2_find_repeated_elements.md | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/Programming Ques/Q2_find_repeated_elements.md b/Programming Ques/Q2_find_repeated_elements.md index 57a1964..f22d0aa 100644 --- a/Programming Ques/Q2_find_repeated_elements.md +++ b/Programming Ques/Q2_find_repeated_elements.md @@ -1,6 +1,6 @@ --- title: Find Repeated Elements -tags: ['set', 'filtering'] +tags: ['set', 'filtering','lambda'] --- # Problem Statement @@ -12,7 +12,7 @@ Given a list, return a list containing elements which are repeated, equal. (case input list -> [1, 2, 3, 2, 3, 3, 4,'A','b','B','A'] #here 2,3,'A' have repetitions output list -> [2, 3, 'A'] ``` - +**Don't use loops. Use functional programming like lambda/map etc...** # Solution ```python test.py -r 'python test.py' @@ -37,7 +37,7 @@ def find_repeated_elements(data: list) -> list: -{% include '../function_type_and_modify_check_suffix.py.jinja' %} +{% include '../is_equal_loops_modify_check_suffix.py.jinja' %} ``` @@ -46,9 +46,10 @@ def find_repeated_elements(data: list) -> list: ## Input 1 ``` -is_equal( - find_repeated_elements([1, 2, 3, 2, 4, 5, 3, 6, 1]), [1, 2, 3] - ) +if not check_for_loops(find_repeated_elements): + is_equal( + find_repeated_elements([1, 2, 3, 2, 4, 5, 3, 6, 1]), [1, 2, 3] + ) ``` ## Output 1 @@ -60,9 +61,10 @@ is_equal( ## Input 2 ``` -is_equal( - find_repeated_elements(['apple', 'banana', 'apple', 'cherry', 'banana']), ['apple', 'banana'] - ) +if not check_for_loops(find_repeated_elements): + is_equal( + find_repeated_elements(['apple', 'banana', 'apple', 'cherry', 'banana']), ['apple', 'banana'] + ) ``` ## Output 2 @@ -73,9 +75,10 @@ is_equal( ## Input 3 ``` -is_equal( - find_repeated_elements([10, 20, 30, 40]), [] - ) +if not check_for_loops(find_repeated_elements): + is_equal( + find_repeated_elements([10, 20, 30, 40]), [] + ) ``` ## Output 3 @@ -89,18 +92,19 @@ is_equal( ## Input 1 ``` -is_equal( - find_repeated_elements([7, 7, 7, 7, 7]), - [7] -) -is_equal( - find_repeated_elements([1, 2, 'apple', 2, 'banana', 'apple','bAnana']), - [2, 'apple'] -) -is_equal( - find_repeated_elements([]), - [] -) +if not check_for_loops(find_repeated_elements): + is_equal( + find_repeated_elements([7, 7, 7, 7, 7]), + [7] + ) + is_equal( + find_repeated_elements([1, 2, 'apple', 2, 'banana', 'apple','bAnana']), + [2, 'apple'] + ) + is_equal( + find_repeated_elements([]), + [] + ) ``` ## Output 1 From 5bb46e49be9e73da561621532f055419ea92d833 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:47:25 +0530 Subject: [PATCH 21/43] Update Q3_process_licenseplate.md From 5eb15403ed2bdbf47c4ba7054abbee376e78331c Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:47:45 +0530 Subject: [PATCH 22/43] Update Q4_Kaprekar_constant.md From e9dfd3efc09acb46203c7e3710e48597e61dd04f Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:49:49 +0530 Subject: [PATCH 23/43] Rename Q1_price_into_dollars.md to Q1_price_into_dollars.md --- .../Q1_price_into_dollars.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Programming Ques => Programming Ques by YASHVI UPADHYAY}/Q1_price_into_dollars.md (100%) diff --git a/Programming Ques/Q1_price_into_dollars.md b/Programming Ques by YASHVI UPADHYAY/Q1_price_into_dollars.md similarity index 100% rename from Programming Ques/Q1_price_into_dollars.md rename to Programming Ques by YASHVI UPADHYAY/Q1_price_into_dollars.md From 7d722b526ef8dc2b8d6aad1ae0888e9a44e99f3c Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:51:02 +0530 Subject: [PATCH 24/43] Update and rename Q2_find_repeated_elements.md to Q2_find_repeated_elements.md --- .../Q2_find_repeated_elements.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Programming Ques => Programming Ques by YASHVI UPADHYAY}/Q2_find_repeated_elements.md (100%) diff --git a/Programming Ques/Q2_find_repeated_elements.md b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md similarity index 100% rename from Programming Ques/Q2_find_repeated_elements.md rename to Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md From cd7d33480fd579e70224bc80890959eb2690c8b5 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:51:20 +0530 Subject: [PATCH 25/43] Update and rename Q3_process_licenseplate.md to Q3_process_licenseplate.md --- .../Q3_process_licenseplate.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Programming Ques => Programming Ques by YASHVI UPADHYAY}/Q3_process_licenseplate.md (100%) diff --git a/Programming Ques/Q3_process_licenseplate.md b/Programming Ques by YASHVI UPADHYAY/Q3_process_licenseplate.md similarity index 100% rename from Programming Ques/Q3_process_licenseplate.md rename to Programming Ques by YASHVI UPADHYAY/Q3_process_licenseplate.md From fc67046db43cc5fb59cefab55c138d6da24b4ea1 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:51:37 +0530 Subject: [PATCH 26/43] Update and rename Q4_Kaprekar_constant.md to Q4_Kaprekar_constant.md --- .../Q4_Kaprekar_constant.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Programming Ques => Programming Ques by YASHVI UPADHYAY}/Q4_Kaprekar_constant.md (100%) diff --git a/Programming Ques/Q4_Kaprekar_constant.md b/Programming Ques by YASHVI UPADHYAY/Q4_Kaprekar_constant.md similarity index 100% rename from Programming Ques/Q4_Kaprekar_constant.md rename to Programming Ques by YASHVI UPADHYAY/Q4_Kaprekar_constant.md From 3350ddbf3646366f8b49139869eeb49f7fc909b2 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 12:53:57 +0530 Subject: [PATCH 27/43] Update Q2_find_repeated_elements.md --- Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md index f22d0aa..b2fdf23 100644 --- a/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md +++ b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md @@ -13,6 +13,7 @@ input list -> [1, 2, 3, 2, 3, 3, 4,'A','b','B','A'] #here 2,3,'A' have repetitio output list -> [2, 3, 'A'] ``` **Don't use loops. Use functional programming like lambda/map etc...** + # Solution ```python test.py -r 'python test.py' From acbd6471d9d6585f2b98980ffbcdd79f6aa4f964 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 13:01:52 +0530 Subject: [PATCH 28/43] Update is_equal_loops_modify_check_suffix.py.jinja --- is_equal_loops_modify_check_suffix.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/is_equal_loops_modify_check_suffix.py.jinja b/is_equal_loops_modify_check_suffix.py.jinja index 9b66170..adb9861 100644 --- a/is_equal_loops_modify_check_suffix.py.jinja +++ b/is_equal_loops_modify_check_suffix.py.jinja @@ -104,7 +104,7 @@ def check_for_loops(func): # Check for any 'for' or 'while' loops for node in ast.walk(tree): if isinstance(node, (ast.For, ast.While)): - print(f"Found a loop (for/while) in the function {func.__name__}.") + print(f"Use of a loop (for/while) in the function {func.__name__} is not allowed.") return True return False From f6ae8d769f08fedb59bc4a1191c79f359f446172 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 13:07:46 +0530 Subject: [PATCH 29/43] Update README.md check for loops --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4dc7880..a0c5f5b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ The 4 Programming Questions evaluate correctly in the local-system:\ ![image](https://github.com/user-attachments/assets/b5ee3a72-0588-4bc9-b634-f6e84d1233be) The type of each question is given below: -1. **Data types** - basic operations on datatypes (str -> f-string, list->indexing, int-> //, %,*) and not used loops. input are handled by a driver code, check the modified list. +1. **Data types** - basic operations on datatypes (str -> f-string, list->indexing, int-> //, %,*) and not used loops. input are handled by a driver code, check the modified list & checked for usage of for/while loop (ignores the docstring, logic to only inspect the function's executable code). 2. **Data Processing** - basic data processing patterns like *mapping, filtering*. input handled by driver code 3. **Data Processing I/O** - inputs from the stdin and print the output to stdout in the specified format (list of dictionaries). 4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly maybe OPPE 2 level) From 10792234cf7cbb596dadf42bfbd7f5618adf9bf6 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 13:09:49 +0530 Subject: [PATCH 30/43] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a0c5f5b..c514816 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ The type of each question is given below: 1. **Data types** - basic operations on datatypes (str -> f-string, list->indexing, int-> //, %,*) and not used loops. input are handled by a driver code, check the modified list & checked for usage of for/while loop (ignores the docstring, logic to only inspect the function's executable code). 2. **Data Processing** - basic data processing patterns like *mapping, filtering*. input handled by driver code 3. **Data Processing I/O** - inputs from the stdin and print the output to stdout in the specified format (list of dictionaries). -4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly maybe OPPE 2 level) +4. **Problem-solving** - An input output based problem-solving which involves **something different from basic data processing patterns.** (good diffcultly but doable by a beginner early weeks of Python IITM learner) From ef8b511f119b3b8d51e56c392c8684e0a0b16794 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 14:11:16 +0530 Subject: [PATCH 31/43] Update Q1_price_into_dollars.md --- .../Q1_price_into_dollars.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Programming Ques by YASHVI UPADHYAY/Q1_price_into_dollars.md b/Programming Ques by YASHVI UPADHYAY/Q1_price_into_dollars.md index 49898eb..891faaf 100644 --- a/Programming Ques by YASHVI UPADHYAY/Q1_price_into_dollars.md +++ b/Programming Ques by YASHVI UPADHYAY/Q1_price_into_dollars.md @@ -5,15 +5,20 @@ tags: ['formatted-string', 'index', 'data-type'] # Problem Statement -Given a list of prices of items in ruppes (1 dollar = 85 rupees), **modify in place the price to dollars and cents(1 dollar = 100 cents)** for the item *at the given index* (don't modify other indices). If the index is out of range, return **None**. -Assume the `price_list` is list of valid **integers**.\ -String output has no decimal points (as the remaining rupees is written as cents)\ -**Don't use any loops**\ +Given a list of prices of items in rupees and an index, **modify that index element in place into price in dollars and cents** (don't modify other indices).\ +**1 dollar = 85 rupees\ +1 dollar = 100 cents** + +- If the `index` is out of range, return **None**. +- Assume the `price_list` is list of valid **integers**. +- String output has no decimal points (as the remaining rupees is written as cents) +- **Refrain from using for/while loops** + **Example:** ```python PriceList = [4000, 7000] get_price_in_dollars(PriceList, 1) # list modified [4000, '82 dollars 35 cents'] -get_price_in_dollars([142, 841, 7621, 2221],1) #list modified [142, '9 dollars 89 cents',7621,1) +get_price_in_dollars([142, 841, 7621, 2221],1) #list modified [142, '9 dollars 89 cents', 7621, 2221] ``` First case: 7000 rupeess -> 82 dollars 35 cents\ Second case: at index=1 is `841` i.e. `9 dollars 89 cents` (85 rupees -> 1 dollar & 1 dollar -> 100 cents) @@ -24,6 +29,7 @@ Second case: at index=1 is `841` i.e. `9 dollars 89 cents` (85 rupees -> 1 dolla ```python test.py -r 'python test.py' @@ -65,7 +63,7 @@ if not check_for_loops(find_repeated_elements): if not check_for_loops(find_repeated_elements): is_equal( order_repr(find_repeated_elements(['apple', 'banana', 'apple', 'cherry', 'banana'])), - "['apple', 'banana']" + order_repr(['apple', 'banana']) ) ``` ## Output 2 From 572c6a7371e3474770d4709d46b4165e2cd12606 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 18:01:24 +0530 Subject: [PATCH 41/43] Update Q2_find_repeated_elements.md --- .../Q2_find_repeated_elements.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md index 0d897c9..29e2b52 100644 --- a/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md +++ b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md @@ -5,7 +5,7 @@ tags: ['set', 'filtering','lambda','data-processing'] # Problem Statement -Given a list, return a str list containing elements **which are repeated**. (case, type sensistive ==, ascending order) +Given a list of any type, return a str list containing elements **which are repeated**. (case, type sensistive ==, ascending order) **Example:** ```python From cd4ff6862c4981720d4d983910377c5ed323b168 Mon Sep 17 00:00:00 2001 From: YashviUp Date: Wed, 8 Jan 2025 18:06:45 +0530 Subject: [PATCH 42/43] Update Q2_find_repeated_elements.md --- .../Q2_find_repeated_elements.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md index 29e2b52..46f9bd4 100644 --- a/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md +++ b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md @@ -5,7 +5,7 @@ tags: ['set', 'filtering','lambda','data-processing'] # Problem Statement -Given a list of any type, return a str list containing elements **which are repeated**. (case, type sensistive ==, ascending order) +Given a list of any type, return a **sorted** list containing elements **which are repeated**. (case, type sensistive ==) **Example:** ```python @@ -22,10 +22,10 @@ def find_repeated_elements(data: list) -> list: ''' Find elements that are repeated in the input list. Argument: - - data: List of items (any type) + - data: List of items (Hint: mixed type need type conversion to sort) Return: - - A list of repeated elements (strings of ascending order) + - A list of repeated elements (ascending order) ''' return ... From 7792084cff0bdebbe4c5712dcf707db5029de0fd Mon Sep 17 00:00:00 2001 From: Yashvi Upadhyay Date: Tue, 14 Jan 2025 11:24:58 +0530 Subject: [PATCH 43/43] Update Q2_find_repeated_elements.md --- .../Q2_find_repeated_elements.md | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md index 46f9bd4..949e6bc 100644 --- a/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md +++ b/Programming Ques by YASHVI UPADHYAY/Q2_find_repeated_elements.md @@ -5,12 +5,12 @@ tags: ['set', 'filtering','lambda','data-processing'] # Problem Statement -Given a list of any type, return a **sorted** list containing elements **which are repeated**. (case, type sensistive ==) +Given a list of any type, return a set containing elements **which are repeated**. (case, type sensistive ==) **Example:** ```python input list -> [1, 2, 3, '2', 3, 3, 4,'A','b','B','A'] #here 3,'A' have repetitions -output list -> [3, 'A'] +output list -> {3, 'A'} ``` **Refrain from for/while loops. Use functional programming like lambda/mapping etc...** @@ -22,16 +22,14 @@ def find_repeated_elements(data: list) -> list: ''' Find elements that are repeated in the input list. Argument: - - data: List of items (Hint: mixed type need type conversion to sort) + - data: List of items Return: - - A list of repeated elements (ascending order) + - A set of repeated elements (order does not matter) ''' return ... - repeated = list(filter(lambda item: data.count(item) > 1, set(data))) - repeated.sort(key=lambda x: (str(x), x)) - return repeated + return set(filter(lambda x: data.count(x) > 1, set(data))) @@ -46,15 +44,15 @@ def find_repeated_elements(data: list) -> list: ``` if not check_for_loops(find_repeated_elements): is_equal( - order_repr(find_repeated_elements([1, 2, 3, 2, 4, 5, 3, 6, 1])), - order_repr([1, 2, 3]) + (find_repeated_elements([1, 2, 3, 2, 4, 5, 3, 6, 1])), + ({1, 2, 3}) ) ``` ## Output 1 ``` -'[1, 2, 3]' +{1, 2, 3} ``` ## Input 2 @@ -62,14 +60,14 @@ if not check_for_loops(find_repeated_elements): ``` if not check_for_loops(find_repeated_elements): is_equal( - order_repr(find_repeated_elements(['apple', 'banana', 'apple', 'cherry', 'banana'])), - order_repr(['apple', 'banana']) + find_repeated_elements(['apple', 'banana', 'apple', 'cherry', 'banana']), + {'apple', 'banana'} ) ``` ## Output 2 ``` -"['apple', 'banana']" +{'apple', 'banana'} ``` ## Input 3 @@ -77,15 +75,15 @@ if not check_for_loops(find_repeated_elements): ``` if not check_for_loops(find_repeated_elements): is_equal( - order_repr(find_repeated_elements([10, 20, 30, 40])), - order_repr([]) + find_repeated_elements([10, 20, 30, 40]), + set() ) ``` ## Output 3 ``` -'[]' +{} ``` # Private Test Cases @@ -95,23 +93,23 @@ if not check_for_loops(find_repeated_elements): ``` if not check_for_loops(find_repeated_elements): is_equal( - order_repr(find_repeated_elements([7, 7, 7, 7, 7])), - order_repr([7]) + find_repeated_elements([7, 7, 7, 7, 7]), + {7} ) is_equal( - order_repr(find_repeated_elements([1, 2, 'apple', 2, 'banana', 'apple', 'bAnana'])), - order_repr([2, 'apple']) + find_repeated_elements([1, 2, 'apple', 2, 'banana', 'apple', 'bAnana']), + {2, 'apple'} ) is_equal( - order_repr(find_repeated_elements([])), - order_repr([]) + find_repeated_elements([]), + set() ) ``` ## Output 1 ``` -'[7]' -"[2, 'apple']" -'[]' +{7} +{'apple', 2} +{} ```